ListPreference text color

╄→尐↘猪︶ㄣ 提交于 2019-12-02 16:51:34

问题


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.The text should be #EEEEEE. I've snipped it but the text colors are applied in each of the given styles.


回答1:


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.




回答2:


Also for radio buttons color add <item name="colorAccent">#000000</item> to your style. Be careful, it's not android:colorAccent but colorAccent



来源:https://stackoverflow.com/questions/46061699/listpreference-text-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!