Carson Holzheimer
Carson Holzheimer

Reputation: 2963

How to change the colour of the Action Bar text in a PreferenceActivity

I've been trying to solve this for 3 hours and haven't found any answers. Here is my v21\styles.xml code. Changing the displayOptions for the action bar here has an effect, but nothing seems to change the colour of the text!

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowBackground">@color/colorBackground</item>
        <item name="android:alertDialogTheme">@style/MyDialogTheme</item>
        <item name="android:color">@color/colorSecondary</item>
    </style>

    <style name="PreferencesTheme" parent="AppTheme">
        <item name="android:textColorPrimary">@color/colorSecondary</item>
        <item name="android:textColorSecondary">@color/colorSecondaryFaded</item>
        <item name="android:listSeparatorTextViewStyle">@style/ListSeparatorText</item>
        <item name="colorControlNormal">@color/colorSecondary</item>
        <item name="actionBarStyle">@style/ActionBarTheme</item>
    </style>

    <style name="ListSeparatorText" parent="android:Widget.TextView">
        <item name="android:background">@color/colorBackgroundLight</item>
        <item name="android:color">@color/colorBackgroundLight</item>
    </style>

    <style name="ActionBarTheme" parent="Widget.AppCompat.Light.ActionBar.Solid">
        <item name="displayOptions">showHome|homeAsUp|showTitle</item>
        <item name="android:textColorPrimary">@color/colorSecondary</item>
        <item name="android:titleTextAppearance">@style/ActionBar.Title</item>

    </style>

    <style name="ActionBar.Title">
        <item name="android:textColorPrimary">@color/colorSecondary</item>
    </style>

And my Settings Activity onCreate, if that's helpful.

public class SettingsActivity extends AppCompatPreferenceActivity {
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setupActionBar();
        getFragmentManager().beginTransaction().replace(android.R.id.content,
                new GeneralPreferenceFragment()).commit();
    }

    /**
     * Set up the {@link android.app.ActionBar}, if the API is available.
     */
    private void setupActionBar() {
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            // Show the Up button in the action bar.
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    }

Upvotes: 1

Views: 907

Answers (1)

Carson Holzheimer
Carson Holzheimer

Reputation: 2963

Well it took me another 4 hours to find this, thanks to another post buried in the internet. I needed to use actionBarTheme instead of actionBarStyle. OMG this was a pain!

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowBackground">@color/colorBackground</item>
        <item name="android:alertDialogTheme">@style/MyDialogTheme</item>

    </style>

    <style name="PreferencesTheme" parent="AppTheme">
        <item name="android:textColorPrimary">@color/colorSecondary</item>
        <item name="android:listSeparatorTextViewStyle">@style/ListSeparatorText</item>
        <!-- This attribute alone sets the colour of the text to the parent text colour-->
        <item name="actionBarTheme">@style/PreferencesTheme.ActionBarTheme</item>
    </style>

    <style name="ListSeparatorText" parent="android:Widget.TextView"><!--parent is optional -->
        <item name="android:background">@color/colorBackgroundLight</item>
        <item name="android:color">@color/colorBackgroundLight</item>
    </style>

    <style name="PreferencesTheme.ActionBarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">
        <!-- THIS is where you can color the arrow -->
        <item name="colorControlNormal">@color/colorBackgroundLight</item>
        <item name="android:textColorPrimary">@color/colorBackground</item>
    </style>

Upvotes: 3

Related Questions