欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

listview改变选中行的字体颜色实例介绍

程序员文章站 2023-08-12 20:28:05
目标:选中item,其字体设置为#3197ff,未选中的,其字体为#ffffff 与listvew设置选中行item背景图片一样,使用selector,不过这里的颜色设置,...
目标:选中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>