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)文章
基于Android10渲染Surface的創(chuàng)建過程
這篇文章主要介紹了基于Android10渲染Surface的創(chuàng)建過程,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-08-08Android編程實(shí)現(xiàn)獲取圖片資源的四種方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)獲取圖片資源的四種方法,分別針對圖片所在目錄位置分析了Android獲取圖片資源的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-11-11Flutter進(jìn)階之實(shí)現(xiàn)動畫效果(九)
這篇文章主要為大家詳細(xì)介紹了Flutter進(jìn)階之實(shí)現(xiàn)動畫效果的第九篇,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-08-08Android開發(fā)升級AGP7.0后的一些適配方法技巧
這篇文章主要為大家介紹了升級AGP7.0后的一些適配方法技巧,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06Android studio報錯:The emulator process for AVD (xxx) was kill
這篇文章主要介紹了Android studio報錯:The emulator process for AVD (xxx) was killed,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12詳解Android USB轉(zhuǎn)串口通信開發(fā)基本流程
本篇文章主要介紹了Android USB轉(zhuǎn)串口通信開發(fā)基本流程,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-04-04Android中RecyclerView實(shí)現(xiàn)滑動刪除與拖拽功能
這篇文章主要使用了RecyclerView的ItemTouchHelper類實(shí)現(xiàn)了Item的拖動和刪除功能,ItemTouchHelper是v7包下的一個類,下面來看看詳細(xì)的介紹吧,需要的朋友可以參考學(xué)習(xí)。2017-02-02