如何更改单选警报对话框的颜色?

时间:2016-12-08 11:14:30

标签: java android

如何更改单选按钮的颜色?下图显示默认情况下单选按钮为蓝色,但我想更改此内容。

enter image description here

我的代码是:

 AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    context);
            alertDialogBuilder.setCustomTitle(promptsView);
            alertDialogBuilder.setItems(frequencyName, null);
            // alertDialogBuilder.setTitle("SELECT FREQUENCY");


            alertDialogBuilder.setSingleChoiceItems(frequencyName, -1, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {

                    selectedFre = frequencyName[i];
                }
            });

            alertDialogBuilder
                    .setCancelable(false)
                    .setPositiveButton("OK",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {

                                    txtFrequency.setText(selectedFre);
                                }
                            })
                    .setNegativeButton("Cancel",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();
                                }
                            });


            AlertDialog alertDialog = alertDialogBuilder.create();


            alertDialog.show();

1 个答案:

答案 0 :(得分:2)

AlertDialog

创建相应的样式
<style name="MaterialThemeDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="colorAccent">@color/action_bar_background</item>
</style>

使用该样式创建AlertDialog.Builder,如下例所示。

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            getActivity(),
            R.style.MaterialThemeDialog);
    alertDialogBuilder.setTitle(R.string.image_resolution);
    alertDialogBuilder.setSingleChoiceItems(R.array.quality_labels, getPosition(), this);

    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();