更改偏好主题颜色

Changing preference theme color

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

我变绿了:

当我创建自己的元素时,在我自己的对话框中,元素采用我的 colorAccent 值的颜色,我想在首选项对话框中实现相同的效果:

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

<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>