对话框中的自定义复选框样

ypr*_*rez 13 checkbox android android-theme android-dialog android-styles

我正在构建一个包含多项选项(复选框)的对话框:

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setMultiChoiceItems(arrayResource, selectedItems, new DialogInterface.OnMultiChoiceClickListener() {
    // ...
});

AlertDialog dialog = builder.create();
dialog.show();
Run Code Online (Sandbox Code Playgroud)

我有一个复选框的自定义样式:

<style name="CustomCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox">
    <item name="android:button">@drawable/btn_check</item>
    <item name="android:textColor">@android:color/holo_purple</item>
</style>
Run Code Online (Sandbox Code Playgroud)

通过设置应用于布局中的各个复选框时,它可以很好地工作style="@style/CustomCheckBox".

但是,如何将此样式应用于创建的对话框?或者对整个主题来说......

如果它有点相关 - 我正在使用minSdkVersion=14targetSdkVersion=19.


更新:

现在根据MattMatt的回答,我将自定义复选框样式应用于整个主题,并为对话框设置自定义样式:

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:checkboxStyle">@style/CustomCheckBox</item>
    <item name="android:dialogTheme">@style/CustomDialog</item>
    <item name="android:alertDialogTheme">@style/CustomDialog</item>
</style>

<style name="CustomCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox">
    <item name="android:button">@drawable/btn_check</item>
    <item name="android:checkMark">@drawable/btn_check</item>
</style>

<style name="CustomDialog" parent="@android:style/Theme.Holo.Light.Dialog">
    <item name="android:checkboxStyle">@style/CustomCheckBox</item>
    <item name="android:background">#aaf</item>
</style>
Run Code Online (Sandbox Code Playgroud)

现在添加到布局的任何复选框都会获得自定义样式,我可以更改对话框的背景,但对话框中的复选框不会受到任何影响......

mik*_*ate 11

实际上,调用setMultiChoiceItems不会生成CheckBox小部件,而是生成CheckedTextView小部件.[更新]似乎更改checkMark属性的值没有任何效果.但是,通过更改CustomDialog样式的listChoiceIndicatorMultiple属性的值,我能够更改选项的drawable.像这样:

<style name="CustomDialog" parent="@android:style/Theme.Holo.Light.Dialog">
    <item name="android:listChoiceIndicatorMultiple">@drawable/btn_check</item>
    <item name="android:background">#aaf</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我通过查看Android源代码发现了这一点,并发现对话框中用于多项选项的模板是这样的:

https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/select_dialog_multichoice_holo.xml