Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
710 views
in Technique[技术] by (71.8m points)

android - ListPreference text color

I'm having a hard time trying to style a ListPreference.

I've applied a main theme which declares a preferenceTheme and both of them link to a dialogTheme (and alertDialogTheme respectively). It works except that the text color of the items doesn't change - but the color of all other texts does. I cannot rely on a workaround because I'm using the v7 preferences and thus cannot override the dialog methods in a custom class.
For me it looks like the rows ignore the text color value, but maybe someone else has a solution for this. Otherwise this might be a bug?

Main style:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- [...] -->        
    <!-- Some color values -->

    <item name="android:dialogTheme">@style/DialogTheme</item>
    <item name="android:alertDialogTheme">@style/DialogTheme</item>
    <item name="dialogTheme">@style/DialogTheme</item>
    <item name="alertDialogTheme">@style/DialogTheme</item>
    <item name="preferenceTheme">@style/PreferenceTheme</item>

</style>


PreferenceTheme:

<style name="PreferenceTheme" parent="PreferenceThemeOverlay.v14.Material">
    <!-- [...] -->
    <!-- Some color values -->
    <item name="android:textColor">@color/preference_primary_color</item>
    <item name="android:textColorPrimary">@color/preference_primary_color</item>
    <item name="android:textColorSecondary">@color/preference_primary_color</item>
    <item name="android:textColorHighlight">@color/preference_primary_color</item>
    <item name="android:editTextColor">@color/preference_primary_color</item>

    <item name="android:dialogTheme">@style/DialogTheme</item>
    <item name="android:alertDialogTheme">@style/DialogTheme</item>
    <item name="preferenceTheme">@style/PreferenceTheme</item>
</style>


DialogTheme:

<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:textColor">#EEEEEE</item>
    <item name="android:textColorPrimary">#EEEEEE</item>
    <item name="android:textColorSecondary">#EEEEEE</item>
    <item name="android:textColorHighlight">#EEEEEE</item>
    <item name="android:textColorTertiary">#EEEEEE</item>
    <item name="android:textColorAlertDialogListItem">#EEEEEE</item>
    <item name="android:editTextColor">#EEEEEE</item>

    <item name="color">#EEEEEE</item>
</style>

This is how it looks.
This is how it looks.The text should be #EEEEEE. I've snipped it but the text colors are applied in each of the given styles.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You did everything right, except one thing: do not use the android prefix when overriding textColorAlertDialogListItem because this is not the framework version of AlertDialog.

This statement is generally true for almost all attributes that belong to the support widgets / views. The reason is pretty straightforward: not all attributes are available on the older platforms. Such example is android:colorControlActivated which was introduced in API 21. The AppCompat lib declares its own colorControlActivated so it's available on older API levels, too. In this case the developer should not use the android prefix when defining the style in the theme as that would point to the platform version of the attribute instead of the AppCompat one.

TL;DR: Do not use the android prefix for support widgets unless you have to (i.e. you get compilation error).


P.S.: I have created a fix / extension to the support preferences-v7 lib's annoying things that you might want to check out.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...