Tima
Tima

Reputation: 12905

TextView with drawableTop and textcolor

This is my textview. It has also an image selector as on its top.

    <TextView
        android:id="@+id/icon_live_ticker" 
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:drawableTop="@drawable/selector_live_ticker" 
        android:gravity="center" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:textStyle="bold"             
        android:textSize="10dp"
        android:text="@string/text_icon_live_ticker">
    </TextView> 

The problem is, that if I set textColor, there are no state changes of the image selector to see anymore.

Can anybody explain why does it happen?

Upvotes: 1

Views: 2316

Answers (1)

Tima
Tima

Reputation: 12905

And the solution is, to use a color-selector for textColor

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_pressed="false"
        android:color="#777777" />
    <item
        android:state_pressed="true"
        android:color="#AAAAAA" />
</selector>

And so modificated TextView looks like:

    <TextView
        android:id="@+id/icon_live_ticker" 
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:drawableTop="@drawable/selector_live_ticker" 
        android:gravity="center" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:textStyle="bold"             
        android:textSize="10dp"
        android:textColor="@drawable/selector_icon_text_color"
        android:text="@string/text_icon_live_ticker">
    </TextView>

I wrote a small post for that: http://hello-android.blogspot.com/2011/01/problem-with-textcolor-by-using.html

Upvotes: 4

Related Questions