listview改變選中行的字體顏色實(shí)例介紹
更新時(shí)間:2013年06月19日 15:38:39 作者:
選中item,其字體設(shè)置為#3197FF,未選中的,其字體為#FFFFFF,下面與大家分享下listview怎么改變選中行字體顏色,感興趣的朋友可以參考下哈
目標(biāo):選中item,其字體設(shè)置為#3197FF,未選中的,其字體為#FFFFFF
與listvew設(shè)置選中行item背景圖片一樣,使用selector,不過(guò)這里的顏色設(shè)置,應(yīng)該是在listview中的textview中設(shè)置。
<SPAN style="COLOR: #666666"><?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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></SPAN>
同樣,定義itemcolor.xml文件,修改選中行的字體顏色:
<SPAN style="COLOR: #666666"><?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 沒(méi)有焦點(diǎn)時(shí)字體顏色 -->
<item
android:state_selected="false"
android:color="#FFFFFF"/>
<!--選中時(shí)的字體顏色 -->
<item
android:state_selected="true"
android:color="#3197FF"/>
<!-- 非觸摸模式下獲得焦點(diǎn)并單擊時(shí)的字體顏色 -->
<item
android:state_focused="true"
android:state_pressed="true"
android:color="#3197FF"/>
</selector></SPAN>
與listvew設(shè)置選中行item背景圖片一樣,使用selector,不過(guò)這里的顏色設(shè)置,應(yīng)該是在listview中的textview中設(shè)置。
復(fù)制代碼 代碼如下:
<SPAN style="COLOR: #666666"><?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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></SPAN>
同樣,定義itemcolor.xml文件,修改選中行的字體顏色:
復(fù)制代碼 代碼如下:
<SPAN style="COLOR: #666666"><?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 沒(méi)有焦點(diǎn)時(shí)字體顏色 -->
<item
android:state_selected="false"
android:color="#FFFFFF"/>
<!--選中時(shí)的字體顏色 -->
<item
android:state_selected="true"
android:color="#3197FF"/>
<!-- 非觸摸模式下獲得焦點(diǎn)并單擊時(shí)的字體顏色 -->
<item
android:state_focused="true"
android:state_pressed="true"
android:color="#3197FF"/>
</selector></SPAN>
相關(guān)文章
Android動(dòng)態(tài)表格的實(shí)現(xiàn)代碼(內(nèi)容、樣式可擴(kuò)縮)
這篇文章主要介紹了Android動(dòng)態(tài)表格的實(shí)現(xiàn)代碼(內(nèi)容、樣式可擴(kuò)縮),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-09-09
Android中ACTION_CANCEL的觸發(fā)機(jī)制與滑出子view的情況
這篇文章主要介紹了Android中ACTION_CANCEL的觸發(fā)機(jī)制與滑出子view的情況,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-09-09
Android 網(wǎng)絡(luò)請(qǐng)求框架Volley實(shí)例詳解
這篇文章主要介紹了Android 網(wǎng)絡(luò)請(qǐng)求框架Volley實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-06-06
Android APK 32位和64位的區(qū)別及說(shuō)明
這篇文章主要介紹了Android APK 32位和64位的區(qū)別及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11
Android ListView實(shí)現(xiàn)上拉加載更多和下拉刷新功能
這篇文章主要為大家詳細(xì)介紹了Android ListView實(shí)現(xiàn)上拉加載更多和下拉刷新功能,介紹了ListView刷新原理及實(shí)現(xiàn)方法,感興趣的小伙伴們可以參考一下2016-05-05
解決android studio中使用monitor工具無(wú)法打開(kāi)data文件夾問(wèn)題
這篇文章主要介紹了解決android studio中使用monitor工具無(wú)法打開(kāi)data文件夾問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04

