ListPreference文字颜色 [英] ListPreference text color

查看:389
本文介绍了ListPreference文字颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难设置ListPreference的样式.

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

我应用了一个主主题,该主题声明了preferenceTheme,并且这两个主题都链接到一个dialogTheme(分别为alertDialogTheme).它的工作原理是项目的文本颜色不变,但所有其他文本的颜色不变.我不能依靠变通方法,因为我正在使用v7首选项,因此无法覆盖自定义类中的对话框方法.
对我来说,行似乎忽略了文本颜色值,但也许其他人对此有解决方案.否则这可能是一个错误吗?

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?

主要风格:

<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:


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>


外观如下.文字应为#EEEEEE.我已将其剪短,但是在每种给定样式中都应用了文本颜色.


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.

推荐答案

您所做的一切都正确,除了一件事:覆盖textColorAlertDialogListItem时不要使用android前缀,因为这不是AlertDialog的框架版本

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.

对于几乎所有属于支持小部件/视图的属性,此语句通常适用.原因很简单:并非所有属性都在较旧的平台上可用.这样的示例是API 21中引入的android:colorControlActivated.AppCompat库声明了自己的colorControlActivated,因此它也可以在较旧的API级别上使用.在这种情况下,开发人员在主题中定义样式时不应使用android前缀,因为这将指向该属性的平台版本,而不是AppCompat版本.

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:除非必要,否则请勿将android前缀用于支持小部件.

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

PS:我已经为支持创建了修复/扩展 preferences-v7 lib可能会让您烦恼的东西.

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

这篇关于ListPreference文字颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆