listview改變選中行的字體顏色實例介紹
更新時間:2013年06月19日 15:38:39 作者:
選中item,其字體設置為#3197FF,未選中的,其字體為#FFFFFF,下面與大家分享下listview怎么改變選中行字體顏色,感興趣的朋友可以參考下哈
目標:選中item,其字體設置為#3197FF,未選中的,其字體為#FFFFFF
與listvew設置選中行item背景圖片一樣,使用selector,不過這里的顏色設置,應該是在listview中的textview中設置。
<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">
<!-- 沒有焦點時字體顏色 -->
<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></SPAN>
與listvew設置選中行item背景圖片一樣,使用selector,不過這里的顏色設置,應該是在listview中的textview中設置。
復制代碼 代碼如下:
<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">
<!-- 沒有焦點時字體顏色 -->
<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></SPAN>
相關文章
基于Android10渲染Surface的創(chuàng)建過程
這篇文章主要介紹了基于Android10渲染Surface的創(chuàng)建過程,文章圍繞主題展開詳細的內容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-08-08Android開發(fā)升級AGP7.0后的一些適配方法技巧
這篇文章主要為大家介紹了升級AGP7.0后的一些適配方法技巧,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-06-06Android studio報錯:The emulator process for AVD (xxx) was kill
這篇文章主要介紹了Android studio報錯:The emulator process for AVD (xxx) was killed,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-12-12Android中RecyclerView實現(xiàn)滑動刪除與拖拽功能
這篇文章主要使用了RecyclerView的ItemTouchHelper類實現(xiàn)了Item的拖動和刪除功能,ItemTouchHelper是v7包下的一個類,下面來看看詳細的介紹吧,需要的朋友可以參考學習。2017-02-02