listview改變選中行的字體顏色實(shí)例介紹
更新時間:2013年06月19日 15:38:39 作者:
選中item,其字體設(shè)置為#3197FF,未選中的,其字體為#FFFFFF,下面與大家分享下listview怎么改變選中行字體顏色,感興趣的朋友可以參考下哈
目標(biāo):選中item,其字體設(shè)置為#3197FF,未選中的,其字體為#FFFFFF
與listvew設(shè)置選中行item背景圖片一樣,使用selector,不過這里的顏色設(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">
<!-- 沒有焦點(diǎn)時字體顏色 -->
<item
android:state_selected="false"
android:color="#FFFFFF"/>
<!--選中時的字體顏色 -->
<item
android:state_selected="true"
android:color="#3197FF"/>
<!-- 非觸摸模式下獲得焦點(diǎn)并單擊時的字體顏色 -->
<item
android:state_focused="true"
android:state_pressed="true"
android:color="#3197FF"/>
</selector></SPAN>
與listvew設(shè)置選中行item背景圖片一樣,使用selector,不過這里的顏色設(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">
<!-- 沒有焦點(diǎn)時字體顏色 -->
<item
android:state_selected="false"
android:color="#FFFFFF"/>
<!--選中時的字體顏色 -->
<item
android:state_selected="true"
android:color="#3197FF"/>
<!-- 非觸摸模式下獲得焦點(diǎn)并單擊時的字體顏色 -->
<item
android:state_focused="true"
android:state_pressed="true"
android:color="#3197FF"/>
</selector></SPAN>
相關(guān)文章
Android動態(tài)表格的實(shí)現(xiàn)代碼(內(nèi)容、樣式可擴(kuò)縮)
這篇文章主要介紹了Android動態(tài)表格的實(shí)現(xiàn)代碼(內(nèi)容、樣式可擴(kuò)縮),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-09-09
Android中ACTION_CANCEL的觸發(fā)機(jī)制與滑出子view的情況
這篇文章主要介紹了Android中ACTION_CANCEL的觸發(fā)機(jī)制與滑出子view的情況,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-09-09
Android 網(wǎng)絡(luò)請求框架Volley實(shí)例詳解
這篇文章主要介紹了Android 網(wǎng)絡(luò)請求框架Volley實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-06-06
Android ListView實(shí)現(xiàn)上拉加載更多和下拉刷新功能
這篇文章主要為大家詳細(xì)介紹了Android ListView實(shí)現(xiàn)上拉加載更多和下拉刷新功能,介紹了ListView刷新原理及實(shí)現(xiàn)方法,感興趣的小伙伴們可以參考一下2016-05-05
解決android studio中使用monitor工具無法打開data文件夾問題
這篇文章主要介紹了解決android studio中使用monitor工具無法打開data文件夾問題,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-04-04

