更改首选项主题颜色

时间:2015-11-11 14:07:37

标签: android android-preferences

如何更改首选项对话框中的元素颜色。

我变绿了:

enter image description here

当我创建自己的元素时,在我自己的对话框中,元素从我的colorAccent值中获取颜色,我希望在首选项对话框中实现相同的颜色:

enter image description here

1 个答案:

答案 0 :(得分:4)

您应该为对话框创建自定义样式。例如,像这里:

<style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:textColor">@color/n1</item>
    <item name="android:textColorPrimary">@color/n2</item>
    <item name="colorAccent">@color/your_color</item>
</style>

并在对话框片段中设置自定义样式:

    @Override
    @NonNull
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        ....
        Context context = new ContextThemeWrapper(getContext(), R.style.AlertDialogStyle);
        ....
    }

您也可以从样式中设置它:

<style name="AppTheme" parent="BaseAppTheme">
    <item name="alertDialogTheme">@style/AlertDialogStyle</item>
    ....
</style>
相关问题