Mateusz Kaflowski
Mateusz Kaflowski

Reputation: 2367

Changing preference theme color

How can I change the element color in the preference dialog.

I get green:

enter image description here

When I create my own elements, in my own dialog, elements take the color from my colorAccent value, and I would like to achieve the same in the preferences dialogue:

enter image description here

Upvotes: 1

Views: 719

Answers (1)

winston
winston

Reputation: 875

You should create custom style for your dialog. Eg, like here:

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

And in your dialog fragment set custom style:

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

Also you can set it from styles:

<style name="AppTheme" parent="BaseAppTheme">
    <item name="alertDialogTheme">@style/AlertDialogStyle</item>
    ....
</style>

Upvotes: 4

Related Questions