Changer la couleur du text dynamiquement
Bonjour à tous,
J'ai un problème que j'arrive vraiment pas à gérer.:cry:
En fait j'ai un linearLayout qui content 2 textView et 1 imageView, ce que je souhaite c'est que les textView change en fonction de l'état :
focused, pressed et selected.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| <LinearLayout android:layout_width="fill_parent" android:id="@+id/importLayout"
android:layout_height="wrap_content" android:orientation="horizontal"
android:paddingBottom="10dip" android:background="@drawable/selector_layout"
android:focusable="true"
>
<LinearLayout android:layout_height="wrap_content"
android:layout_weight="1" android:orientation="vertical"
android:layout_width="fill_parent">
<TextView android:layout_width="fill_parent" android:id="@+id/import_spam_title"
android:layout_height="wrap_content" android:layout_gravity="center"
android:text="@string/import_spam"
android:textSize="17dip" android:layout_marginLeft="10dip"
android:layout_marginRight="10dip" android:textStyle="bold"
android:layout_marginTop="10dip" android:duplicateParentState='true'
/>
<TextView android:layout_width="fill_parent" android:id="@+id/textImportSpam"
android:layout_height="wrap_content" android:layout_gravity="center"
android:text="@string/description_import_spam"
android:layout_marginLeft="10dip" android:duplicateParentState='true'
android:layout_marginRight="10dip" android:textSize="13dip"/>
</LinearLayout>
<ImageView android:src="@drawable/custom_arow_list"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="10dip" android:layout_gravity="center"
android:layout_marginTop="5dip" />
</LinearLayout> |
Pour cela j'ai crée un drawable qui prend différents états:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_enabled="false"
android:color="@color/white" />
<item android:state_enabled="false" android:state_pressed="true"
android:color="@color/white" />
<item android:state_enabled="true" android:color="@color/white" />
<item android:color="@color/DarkGrey" />
</selector> |
et franchement rien à faire, le text ne change jamais de couleur.
Avez vous des suggestions SVP.
Merci d'avance.