Change Listview Textcolor

Hi, I am using listview which have several elements adding dynamically .. I want to change the color of the text of the listitem of any idea

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#659EC7"> <ImageView android:id="@+id/icon" android:layout_width="72px" android:layout_height="wrap_content" android:layout_marginTop="5px" /> <TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingTop="5px" android:paddingBottom="5px"> <TextView android:id="@+id/item1" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/item2" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:paddingTop="30px" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:background="@android:color/darker_gray"/> </TwoLineListItem> </LinearLayout> 

I am using 2linelistIem

+4
source share
2 answers

Here is the code I wrote and used: It supports the Android style for all other states. it just imposes a transparent state on the desired color:

Layer list for viewing a list with a custom background

as you can see in my question, there is a minor bug with a focused state, but this is still the best solution I've ever seen: D

+1
source

Use this type of technique to dynamically change color:

 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:drawable="@color/black" /> <!-- focused --> <item android:state_focused="true" android:state_pressed="true" android:drawable="@color/black" /> <!-- focused and pressed--> <item android:state_pressed="true" android:drawable="@color/green" /> <!-- pressed --> <item android:drawable="@color/black" /> <!-- default --> </selector> 
+1
source

All Articles