Search code examples
androidandroid-preferencesandroid-theme

Android PreferenceFragment title text color


I'm using a AppCompatPreferenceActivity that uses a PreferenceActivity simplified UI for phones (no fragments), but a two-pane UI with PreferenceFragment when it's a tablet.

Until now, I used only a light theme (my theme's parent is Theme.AppCompat.Light) and no problem, it looks like this when in two-pane mode:

enter image description here

I'm now implementing a dark theme, so this time, my theme's parent is "Theme.AppCompat".

And it looks like this:

enter image description here

As you can see, the title of the preference fragment is black on a dark grey background. How can I set this "title" color?

Note: on Pre-Lollipop, it was easy, we would just have to att that to the preference activity theme:

<item name="android:textColorSecondary">#AAAAAA</item>

... but it doesn't work anymore on Lollipop and Marshmallow.

Any idea?


Solution

  • By checking the PreferenceActivity code, I eventually found that the title on the right pane is not part of the preference fragment, but is the fragment "breadcrumb".

    By searching for an answer with this keyword ("breadcrumb"), I saw that someone already asked the same thing, and the accepted answer is great and details all about how to do it, and why it's a little more complicated than just changing a color in a style.

    Here's the question: Changing the highlight and title color for fragments in PreferenceActivity

    And the direct link to the answer: https://stackoverflow.com/a/27078485/1534408