开发者

TextView inside a ListView: setTextHighlightColor() issue

I have ListView and TextView inside it. Now the thing is: I want to change the TextColor over the cell's selection in the ListView, but setting setTextHighlightColor of TextView isn't giving this output.

I have tried setting a selector for this, but that is not helping too.

Can this be solved? What might be causing the issue to populate?

The code layout is:

Cell.xml

<ImageView 
    android:id="@+id/thumbnail" 
    android:layout_width="48dip"
    android:layout_height="48dip" 
   开发者_C百科 android:layout_gravity="center_vertical"
    android:src="@drawable/icon" 
/>
<TextView 
    android:id="@+id/username" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@id/thumbnail"
    android:layout_alignParentTop="true"
    android:gravity="top" 
    android:text="Username" 
    android:textColor="@drawable/timeline_username_selector"
/>
<TextView 
    android::id="@+id/time" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true"
    android:layout_marginLeft="10px"
    android:text="31stMarch,2010" 
    android:textColor="@drawable/timeline_username_selector"
/>

<TextView 
    android:id="@+id/textTweet" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:layout_below="@+id/username"
    android:layout_toRightOf="@id/thumbnail"
    android:layout_alignParentBottom="true"
    android:gravity="top" 
    android:textColor="@drawable/timeline_tweet_selector"
/>

The Selector is a simple one


As you know, you'll need a state drawable to show different colors for different states:

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

Make sure to pass the selected state from the main row view down to child views in the row:

android:duplicateParentState="true"
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜