listview改變選中行字型顏色
阿新 • • 發佈:2019-02-01
目標:選中item,其字型設定為#3197FF,未選中的,其字型為#FFFFFF。其效果圖如下:
與listvew設定選中行item背景圖片一樣,使用selector,不過這裡的顏色設定,應該是在listview中的textview中設定。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<? xml
version="1.0" encoding="utf-8"?>
< TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
< TableRow
>
< TextView
android:id="@+id/name_tv"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="25px"
android:textColor="@drawable/itemcolor">
</ TextView >
</ TableRow >
</ TableLayout >
|
同樣,定義itemcolor.xml檔案,修改選中行的字型顏色:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<? xml
version="1.0" encoding="utf-8" ?>
<!-- 沒有焦點時字型顏色 -->
< item
android:state_selected="false"
android:color="#FFFFFF"/>
<!--選中時的字型顏色 -->
< item
android:state_selected="true"
android:color="#3197FF"/>
<!-- 非觸控模式下獲得焦點並單擊時的字型顏色 -->
< item
android:state_focused="true" android:state_pressed="true"
android:color="#3197FF"/>
</ selector >
|