当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Text Color not changing on click

问题描述:

I have a List View and i am setting the background of the list item with the selector.

list_selecter.xml :

 <?xml version="1.0" encoding="utf-8"?>

<!-- focused and pressed -->

<item android:drawable="@color/darkred" android:state_pressed="true"/>

<item android:drawable="@android:color/transparent" android:state_pressed="false"/>

<!-- pressed -->

<item android:drawable="@color/darkred"/>

Layout for the List Item is :

 <?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:background="@drawable/list_selecter"

android:orientation="vertical"

android:padding="10dp" >

<TextView

xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/newsHeadingText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginRight="20dp"

android:textColor="@color/text_selector" />

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_centerVertical="true"

android:layout_marginLeft="5dp"

android:background="@drawable/aerow" />

<TextView

xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/newsText"

android:layout_width="200dip"

android:layout_height="wrap_content"

android:layout_below="@id/newsHeadingText"

android:textColor="#736F6E" />

</RelativeLayout>

And the text_selector.xml for the text color change:

 <?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_selected="true" android:color="@android:color/white"/>

<item android:state_focused="true" android:color="@android:color/white"/>

<item android:state_pressed="true" android:color="@android:color/white"/>

<item android:color="@android:color/black"/>

</selector>

Text color is not getting changed on the selection. What could be the issue?

网友答案:

Specify android:duplicateParentState='true' on your TextView

分享给朋友:
您可能感兴趣的文章:
随机阅读: