简体   繁体   中英

How to change the color of single choice alert dialog?

How do I change the colour of a radio button? The image below shows that the radio buttons are blue by default but I would like to change this.

在此处输入图片说明

My code is:

 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();

Create corresponding style for AlertDialog

<style name="MaterialThemeDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="colorAccent">@color/action_bar_background</item>
</style>

Create AlertDialog.Builder using that style like below example.

    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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM