0
votes

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?

3

3 Answers

2
votes

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

0
votes

Did you try like this?

in styles.xml

<style name="PreferenceScreen" parent="YourApplicationThemeOrNone">
    <item name="android:textColor">@color/TitleColor</item>
</style>

in Manifest

<activity
      android:name="MyPreferenceActivity"
      ...
      android:theme="@style/PreferenceScreen" >
</activity>
0
votes

I changed it by overriding Category theme.

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
    //other stuff
    <item name="preferenceTheme">@style/MyPrefTheme</item>
</style>

<style name="MyPrefTheme" parent="@style/PreferenceThemeOverlay">
    <item name="preferenceCategoryStyle">@style/CategoryStyle</item>
    <item name="android:preferenceCategoryStyle">@style/CategoryStyle</item>
</style>

<style name="CategoryStyle" parent="Preference.Category">
    <item name="android:layout">@layout/category_view</item>
</style>

layout/category_view.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@android:id/title"
          style="?android:attr/listSeparatorTextViewStyle"
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:textColor="@color/white"
          android:layout_height="wrap_content"
    />

to know more visit Preference style.xml