我已经找了几天了,但是找不到一个我现在能找到工作的答案。
我想允许用户在一个列表中为整个应用程序选择不同的主题,用于白天/晚上的目的。
问题是我找不到更改listpreference行项目textcolor的文本颜色的方法。我发现的一些解决方案是使用属性

<item name="android:textColorPrimary">@color/red_color</item>

以设置该文本。但是,在我使用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>

这是显示首选项片段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>

基本上我要问的问题是:
-如何在ListPreference中更改条目文本颜色?
Web上的一些文章正在解释如何创建自定义ListPreference视图,如本文Custom ListPreference
创建curstom视图是更改文本颜色的唯一方法还是listpreference视图缺少属性?
我是一个android新手,刚从coursera mooc中出来创建这个开源应用程序。

最佳答案

您可以更改主题定义中属性android:textColorAlertDialogListItem的值,如下所示。

<item name="android:textColorAlertDialogListItem">@color/white</item>

这对我很有用。祝你好运!!

07-24 19:18
查看更多