6

I'm searching for this for a couple of days but cannot find an answer that I can manage to get working for now.

I would like to allow the user to select in a list different themes for the whole application for day/night purposes. The issue is that I can't find a way to change the colors of the text for a ListPreference row Item textColor. Some solutions I've found are talking about using the attribute

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

in the style in order to set that text. However this has no effect during my tests using API 11. The results I obtained after many attempts is almost always the same: When setting different styles for the application I can change the title color for the ListPreference but not the row items text color:

Here is the screenshot :

Screenshot

These are the styles I am using:

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

This is the display preference fragment xml file

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

Basically the question I'm asking is: - How to change the color of the entries text color in a ListPreference?

Some articles on the web are explaining how to create custom ListPreference view such as this article Custom ListPreference

  • Is creating a curstom view the only way to change the text color or is there an attribute or property that I am missing for the ListPreference View ?

Lots of thanks in advance, I'm a newbie in Android and just got out of the Coursera MOOC to create this open source application.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
user1892410
  • 381
  • 5
  • 12

1 Answers1

9

You can change the value for the attribute android:textColorAlertDialogListItem like below in your theme definition.

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

That worked for me. Good luck!!

user3818225
  • 91
  • 1
  • 2
  • 1
    Thanks but this solution did not work for me, however I used the technique described by @Reinier in http://stackoverflow.com/questions/10460715/how-to-customize-list-preference-radio-button/14790665#14790665 – user1892410 Sep 04 '15 at 18:50
  • 4
    It works without the "android:" prefix, as per this answer https://stackoverflow.com/a/46062360/1276132 – AlexSee May 12 '18 at 21:55
  • What should I do if I want to set different color to each row? – Sasha Balyas Dec 18 '19 at 08:37