开发者

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_ticke开发者_运维技巧r">
    </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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜