如何在android中更改.setpositive按钮和.setnegative按钮的主题颜色

如何在android中更改.setpositive按钮和.setnegative按钮的主题颜色,android,Android,在“自定义警报”对话框中,我包含了.setPositive和.setNegative按钮,我想将默认主题颜色更改为白色。如何更改?请回答。我不想用颜色回答。下面的代码片段 提前感谢 当做 mysmax这样做,但先执行alert.show(),然后更改颜色 AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Stackoverflow answer!")

在“自定义警报”对话框中,我包含了.setPositive和.setNegative按钮,我想将默认主题颜色更改为白色。如何更改?请回答。我不想用颜色回答。下面的代码片段

提前感谢 当做
mysmax

这样做,但先执行alert.show(),然后更改颜色

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Stackoverflow answer!")
            .setPositiveButton("YES", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            })
            .setNegativeButton("NO", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
//Use R.id.button1 and button2 
    ((Button)alert.findViewById(android.R.id.button1)).setBackgroundResource("Set to what you want");

这样做,但要先执行alert.show(),然后再更改颜色

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Stackoverflow answer!")
            .setPositiveButton("YES", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            })
            .setNegativeButton("NO", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
//Use R.id.button1 and button2 
    ((Button)alert.findViewById(android.R.id.button1)).setBackgroundResource("Set to what you want");

对不起,如果这不是你想要的答案,但这是你如何做到的

这是一个默认的警报对话,我不认为你可以自定义,你将不得不作出这样的自定义警报对话

将这些定义为全局变量

AlertDialog alertDialog;
View promptsView;
AlertDialog.Builder alertDialogBuilder;
将以下内容添加到任何导致alertdialogue出现的内容中

 LayoutInflater li = LayoutInflater.from(this));

    View promptsView = li.inflate(R.layout.CustomLayout, null);
    // above I am setting the customview of the alert dialogue


    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            getActivity());

    alertDialogBuilder.setView(promptsView);
    // here I am officially setting the custom layout

    // set dialog message

    alertDialogBuilder.setTitle("Stretch Type");
    // alert dialogue title

    // create alert dialog
    alertDialog = alertDialogBuilder.create();
以及CustomLayout.xml文件
只需添加一个文本视图和两个按钮,一个说“是”,另一个说“否”或任何你想让他们说的话

对不起,如果这不是你想要的答案,但你就是这样做的

这是一个默认的警报对话,我不认为你可以自定义,你将不得不作出这样的自定义警报对话

将这些定义为全局变量

AlertDialog alertDialog;
View promptsView;
AlertDialog.Builder alertDialogBuilder;
将以下内容添加到任何导致alertdialogue出现的内容中

 LayoutInflater li = LayoutInflater.from(this));

    View promptsView = li.inflate(R.layout.CustomLayout, null);
    // above I am setting the customview of the alert dialogue


    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            getActivity());

    alertDialogBuilder.setView(promptsView);
    // here I am officially setting the custom layout

    // set dialog message

    alertDialogBuilder.setTitle("Stretch Type");
    // alert dialogue title

    // create alert dialog
    alertDialog = alertDialogBuilder.create();
以及CustomLayout.xml文件 只需添加一个文本视图和两个按钮,一个说“是”,另一个说“否”,或者你想让他们说什么就说什么