Search code examples
javaandroidxmlstylesandroid-preferences

ColorAccent in PreferenceScreen not working correctly in API <=22


I installed API 22 on emulator and noticed that the RadioButtons and Buttons in ListPreferences and Preferences are not changing to the correct color that is stated in the Styles file. On API >22 it works fine. This problem only occurs in the PreferenceScreen that is used in SettingsActivity.

The color I want is #76B900 (Green)

What I get is the default Android light-blue color

RadioButton

Button

Theme is registered in the manifest:

        <activity
            android:name="com.Test.App.SettingsActivity"
            android:label="@string/title_activity_settings"
            android:windowSoftInputMode="adjustPan"
            android:theme="@style/PreferencesTheme"
            android:screenOrientation="portrait"/>

PreferencesTheme (styles.xml):

<style name="PreferencesTheme" parent="Theme.AppCompat">
        <item name="android:windowBackground">@color/background</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:textColorPrimary">@color/primaryText</item>
        <item name="android:textColorSecondary">@color/settingsSubtext</item>
        <item name="android:colorBackground">@color/background</item>
        <item name="android:textColorPrimaryInverse">@color/primaryText</item>
    </style>

PreferencesTheme (styles.xml (v21)):

<style name="PreferencesTheme" parent="Theme.AppCompat">
        <item name="android:windowBackground">@color/background</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:textColorPrimary">@color/primaryText</item>
        <item name="android:textColorSecondary">@color/settingsSubtext</item>
        <item name="android:colorBackground">@color/background</item>
        <item name="android:textColorPrimaryInverse">@color/primaryText</item>
        <item name="android:colorAccent">@color/colorAccent</item>
    </style>

Colors (colors.xml):

    <color name="colorPrimary">#0F0F0F</color> - Black
    <color name="colorPrimaryDark">#000000</color> - Black
    <color name="colorPrimaryLight">#C8E6C9</color> - Light Green
    <color name="colorAccent">#76B900</color> - Green
    <color name="primaryText">#FFFFFF</color> - White
    <color name="secondaryText">#757575</color> - Gray
    <color name="background">#333333</color> - Dark Gray

Default Android light-blue color is not set anywhere in the colors or styles file.


Solution

  • I had a similar issue.

    Add this to your styles file:

    <style name="AlertDialogCustom" parent="android:Theme.Material.Dialog.Alert">
            <item name="colorAccent">@color/colorAccent</item>
            <item name="android:colorAccent">@color/colorAccent</item>
    </style>
    

    Add this to your PreferenceTheme style:

    <item name="android:alertDialogTheme">@style/AlertDialogCustom</item>
    

    Buttons should now be in the correct colorAccent color.