更改setmultichoiceitems中的标准复选框颜色

时间:2016-01-25 06:10:41

标签: android alertdialog android-alertdialog multichoiceitems

我有一个alertdialog,其中包含多项目,所有其他功能都正常。我显示的复选框颜色与我的应用颜色不匹配时出现问题。我已尝试使用setcustombuilder,但它无法正常工作。请帮忙。我不想使用listview。

}

是否有可能将android复选框颜色的颜色更改为其他颜色?

答案:

final String[] ratings = {"2015","2016"};
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
final boolean[] ratingschecked = {false,false};
 builder.setTitle("Select Year");
    builder.setMultiChoiceItems(ratings, ratingschecked, new DialogInterface.OnMultiChoiceClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
           //something
        }
    }).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            //something
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });

    AlertDialog dialog = builder.create();
    builder.show();

然后在App主题中添加此文件。它有效。

 Created a Style file.
         <style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
          <item name="colorAccent">@color/brand</item>
         </style>

2 个答案:

答案 0 :(得分:0)

在styles.xml

中的主题中使用此行
<style>
    <item name="android:colorAccent">@android:color/holo_green_dark</item>
</style>

使用您选择的颜色

答案 1 :(得分:0)

在此链接中,我展示了如何更改multichoiceitems中的标准复选框颜色。它还显示了如何自定义AletDialog。例如,如何更改分隔符colro等。请访问此链接:

https://stackoverflow.com/a/33439849/5475941

我希望它有所帮助。