Roman Novoselov
Roman Novoselov

Reputation: 161

Android. PreferenceActivity. ListPreference. How can I change the backgrounds color of ListPreference?

Implements the "night theme". I don't know how to change the background color of ListPreference.

PreferenceActivity "day" theme

PreferenceActivity night theme

As you can see, only to pick up the color of the title of "night" colors.

I use the following theme:

<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
    <item name="android:textColor">@color/primary_text</item>
    <item name="android:textColorSecondary">@color/secondary_text</item>
    <item name="toolbarStyle">@style/Toolbar</item>
    <item name="android:windowBackground">@color/background_window</item>
    <item name="preferenceTheme">@style/SettingsFragmentStyle</item>
    <item name="colorControlNormal">@color/icons</item>
</style>

<style name="SettingsFragmentStyle" parent="@style/PreferenceThemeOverlay.v14.Material">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="android:textColorPrimary">@color/primary_text</item>
    <item name="android:textColorSecondary">@color/secondary_text</item>
    <item name="android:textColorTertiary">@color/accent</item>
    <item name="android:background">@color/background_window</item>
</style>

What parameters are responsible for:

  1. Backgrounds ListPreference;
  2. Text color ListPreference items;
  3. Color "switches" ListPreference - I want to replace on the "accent" color (orange in my case).

Thanks for the help.

Upvotes: 5

Views: 2272

Answers (2)

Jimale Abdi
Jimale Abdi

Reputation: 2844

First, create a style for your Dialog.

The dialog style

<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:colorBackground">#1E1E1E</item>
<item name="android:textColorSecondary">#D8D8D8</item>
<item name="textColorAlertDialogListItem">#D8D8D8</item>
<item name="color">#80CBC4</item>

then set the dialog style in your main style

<style name="AppNight" parent="Theme.AppCompat.DayNight.DarkActionBar">

    <item name="alertDialogTheme">@style/DialogTheme</item>
</style>

AppNight is my Night theme I didn't mention the other attributes of my theme to minimize the code.

see here how it looks

Upvotes: 3

Robert.M
Robert.M

Reputation: 11

You can add this code below to your dark theme in the styles.xml. It also changes the way the dialog is displayed, so it'll be it's own page instead of the card style.

<item name="android:alertDialogTheme">@style/ThemeOverlay.AppCompat.Dark</item>

Before

After

Otherwise I you have to make a custom alert dialog, Try this How to change theme for AlertDialog

Upvotes: 1

Related Questions