小编use*_*410的帖子

ListPreference项目行文本颜色

我正在寻找这个问题几天但是找不到我能够立即开始工作的答案.

我想允许用户在列表中选择不同的主题用于整个应用程序的日/夜目的.问题是我无法找到一种方法来更改ListPreference行Item textColor的文本颜色.我发现的一些解决方案正在讨论使用该属性

<item name="android:textColorPrimary">@color/red_color</item>
Run Code Online (Sandbox Code Playgroud)

在样式中以设置该文本.但是在使用API​​ 11的测试中这没有任何效果.我在多次尝试后获得的结果几乎总是相同的:当为应用程序设置不同的样式时,我可以更改ListPreference的标题颜色,但不能更改行项目文本颜色:

这是截图:

截图

这些是我使用的样式:

<!-- Application theme. -->
<style name="AppTheme.Daylight" parent="AppBaseTheme">
    <item name="android:background">@color/white</item>
    <item name="android:panelBackground">@color/gray</item>
    <item name="android:textColor">@color/black</item>
</style>

<style name="AppTheme.Dusk" parent="AppBaseTheme">
    <item name="android:background">@color/black</item>
<item name="android:panelBackground">@color/gray</item>
    <item name="android:textColor">@color/salmon</item>
</style>

<style name="AppTheme.Night" parent="AppBaseTheme">
    <item name="android:background">@color/black</item>
    <item name="android:panelBackground">@color/gray</item>
    <item name="android:textColor">@color/red</item>
</style>
Run Code Online (Sandbox Code Playgroud)

这是显示首选项片段xml文件

<PreferenceCategory 
    android:title="@string/preference_display_settings"
    android:key="display_preferences">
    <ListPreference
        android:key="display_mode"
        android:title="@string/preference_display_settings"
        android:entries="@array/preference_display_mode_available"
        android:entryValues="@array/preference_display_mode_values" />
</PreferenceCategory>
Run Code Online (Sandbox Code Playgroud)

基本上我问的问题是: - 如何更改ListPreference中条目文本颜色的颜色?

Web上的一些文章正在解释如何创建自定义ListPreference视图,例如本文Custom ListPreference

  • 创建curstom视图是更改文本颜色的唯一方法,还是我缺少ListPreference视图的属性或属性?

非常感谢,我是Android的新手,刚刚离开Coursera MOOC来创建这个开源应用程序.

android textcolor listpreference

6
推荐指数
1
解决办法
3463
查看次数

标签 统计

android ×1

listpreference ×1

textcolor ×1