Search code examples
androidtextviewandroid-selector

Android selector & text color


I want a simple TextView to behave the way simple_list_item_1 in a ListView does. Here's the XML:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content" android:layout_width="fill_parent"
    android:gravity="center" android:focusable="true"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:background="@android:drawable/list_selector_background" />

Everything works except for the text color that (expectedly) doesn't change in focused state. How do I make it change to textAppearanceLargeInverse?


Solution

  • And selector is the answer here as well.

    Search for bright_text_dark_focused.xml in the sources, add to your project under res/color directory and then refer from the TextView as

    android:textColor="@color/bright_text_dark_focused"