在Android中的AlertDialog中更改CheckBox样式

Rob*_*nda 4 checkbox android selector android-alertdialog

我在更改“警报对话框”的chexbox主题时遇到麻烦。我无法将所选复选框的颜色更改为我的AccentColor。

这是我的风格代码

<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">      
<item name="android:checkboxStyle">@style/CustomCheckBox</item>
</style>
<style name="CustomCheckBox"     parent="android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/activated_checkbox</item>
</style>
Run Code Online (Sandbox Code Playgroud)

选择器:activated_checkbox

 <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- checked -->
<item android:state_checked="true" android:drawable="@color/AccentColor">
</item>
<item android:state_checked="false" android:drawable="@color/White">
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)

和显示AlertDialog的方法。

private void showDialog() {

    final CharSequence[] items = getResources().getStringArray(R.array.tipoDescargas);
    final boolean[] states = {false, false, false};
    AlertDialog.Builder builder = new AlertDialog.Builder(this,R.style.AlertDialogCustom);
    builder.setTitle(getResources().getString(R.string.preguntaDescargas));
    builder.setMultiChoiceItems(items, states, new DialogInterface.OnMultiChoiceClickListener() {
        public void onClick(DialogInterface dialogInterface, int item, boolean state) {
        }
    });
    builder.setPositiveButton("Descargar", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            SparseBooleanArray CheCked = ((AlertDialog) dialog).getListView().getCheckedItemPositions();
            if (CheCked.get(0) && CheCked.get(1) && CheCked.get(2))
                Toast.makeText(getApplication(), "TODOS", Toast.LENGTH_SHORT).show();
            if (CheCked.get(0)) {
                Toast.makeText(getApplication(), "Item 1", Toast.LENGTH_SHORT).show();
            }
            if (CheCked.get(1)) {
                Toast.makeText(getApplication(), "Item 2", Toast.LENGTH_SHORT).show();
            }
            if (CheCked.get(2)) {
                Toast.makeText(getApplication(), "Item 3", Toast.LENGTH_SHORT).show();
            }
        }
    });
    builder.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });builder.create().show();
}
Run Code Online (Sandbox Code Playgroud)

谁能帮我?谢谢

更新1

<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:checkedTextViewStyle">@style/CustomCheckBox</item>
</style>

<style name="CustomCheckBox" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:checkMark">@drawable/activated_checkbox</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我找到了正确显示颜色的解决方案。

<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:listChoiceIndicatorMultiple">@drawable/activated_checkbox</item>
</style>
Run Code Online (Sandbox Code Playgroud)

和选择器

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/checkedcheckbox24"     android:state_checked="true"></item>
<item android:drawable="@drawable/uncheckedcheckbox24"     android:state_checked="false"></item>
</selector>
Run Code Online (Sandbox Code Playgroud)

Rob*_*nda 5

使用此代码,图标可以正确显示

<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:listChoiceIndicatorMultiple">@drawable/activated_checkbox</item>
</style>
Run Code Online (Sandbox Code Playgroud)

和选择器代码

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/checkedcheckbox24"     android:state_checked="true"></item>
<item android:drawable="@drawable/uncheckedcheckbox24"     android:state_checked="false"></item>
</selector>
Run Code Online (Sandbox Code Playgroud)