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
?
Have you tried
setOnFocusChangeListener
? Within the handler, you could change the text appearance.For instance:
You can then apply whatever changes you want when it's focused or not. You can also use the ViewTreeObserver to listen for Global focus changes.
For instance:
I hope this helps or gives you ideas.
If using TextViews in tabs this selector definition worked for me (tried Klaus Balduino's but it did not):
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
In order to make it work on selection in a list view use the following code:
Apparently the key is
state_activated="true"
state.Here is the example of selector. If you use eclipse , it does not suggest something when you click ctrl and space both :/ you must type it.
You can look at for reference;
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
I got by doing several tests until one worked, so: res/color/button_dark_text.xml
res/layout/view.xml