9

The title says it all: how can I style my PreferenceFragmentCompat. My v14/style.xml is

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:editTextStyle">@style/Widget.EditText.White</item>
        <item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
    </style>

    <style name="Widget.EditText.White" parent="@android:style/Widget.EditText">
        <item name="android:textColor">#ffffffff</item>
    </style>
</resources>

The base theme has a black background - the preferences screen is then unreadable as I have black text on that black background.

I've tried many things but I cannot change the text colour.

What I've had to do is to set the fragment container background colour to white whilst the settings fragment is active. An ugly hack and not what I want to have to do.

Kevin Gilbert
  • 671
  • 10
  • 18

2 Answers2

12

To answer my own question: my v14/style.xml is now

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:editTextStyle">@style/Widget.EditText.White</item>
        <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
    </style>

    <style name="Widget.EditText.White" parent="@android:style/Widget.EditText">
        <item name="android:textColor">#ffffffff</item>
    </style>

    <style name="PreferenceThemeOverlay.v14">
        <item name="android:background">@color/settings_background</item>
        <item name="android:textColor">@color/settings_text_colour</item>
        <item name="android:textColorSecondary">@color/settings_text_colour_secondary</item>
    </style>
</resources>

My problem is now to style a ListPreference.

Why is this so hard? If there is any documentation relating to styling preferences, it is well hidden. Grrrrrr!

Kevin Gilbert
  • 671
  • 10
  • 18
  • It's 2019, preference styling is STILL unnatural even with the preference material design v14 support library. Finally made do with *deprecated* workarounds similar to those in your answer... I second your Grrrrrr! >:( – varun Mar 04 '19 at 22:58
  • 3
    It's 2020 and I can find exactly ZERO way to set the text color of a preference (defaults to black, which I use nowhere). And ANOTHER entire day shot to hell. Thanks AGAIN, Android. I third your Grrrrr! >:-( – rmirabelle Apr 08 '20 at 21:27
0

Take a look at README for github project Gericop/Android-Support-Preference-V7-Fix

Alexei Volkov
  • 851
  • 9
  • 11