Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to style PreferenceFragmentCompat

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.

like image 902
Kevin Gilbert Avatar asked Nov 11 '15 00:11

Kevin Gilbert


1 Answers

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!

like image 94
Kevin Gilbert Avatar answered Nov 18 '22 17:11

Kevin Gilbert