Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListPreference item row text color

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.

like image 732
user1892410 Avatar asked Apr 17 '14 02:04

user1892410


1 Answers

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

like image 85
user3818225 Avatar answered Oct 14 '22 15:10

user3818225