android – API级别10上的ListView行选择器?

android – API级别10上的ListView行选择器?,第1张

概述目标是更改ListView的选定行的背景颜色.我在API级别13和16上取得了成功.但是在API级别10(2.3.3)上相同的代码失败了.没有异常抛出但也没有改变颜色. 这就是我的尝试; list_row.xml <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.co 目标是更改ListVIEw的选定行的背景颜色.我在API级别13和16上取得了成功.但是在API级别10(2.3.3)上相同的代码失败了.没有异常抛出但也没有改变颜色.

这就是我的尝试;

List_row.xml

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:background="@drawable/row_bg_colors"    androID:orIEntation="vertical"    androID:padding="8dp"    >    <TextVIEw        androID:ID="@+ID/textVIEw2"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:text="@string/app_name"        androID:textSize="25sp" /></linearLayout>

row_bg_colors.xml

<?xml version="1.0" enCoding="utf-8"?><selector xmlns:androID="http://schemas.androID.com/apk/res/androID">    <!-- selected -->    <item androID:drawable="@color/lightBlue" androID:state_selected="true"/>    <item androID:drawable="@color/lightBlue" androID:state_activated="true"/>    <item androID:drawable="@color/lightBlue" androID:state_focused="true"/>    <item androID:drawable="@color/lightBlue" androID:state_checked="true"/>    <!-- default -->    <item androID:drawable="@drawable/unit_bg"/></selector>

非常简单的适配器,与背景无关.经典ListVIEw对象(未扩展).活动xml文件中ListVIEw上的singleChoice属性.

没有关于兼容性的警告.

那么我缺少一个不受支持的功能吗?或者是什么?

解决方法 将列表选择器添加到列表视图中.那是:

<ListVIEw    androID:ListSelector="@drawable/row_bg_colors"/>

并且还将row_bg_colors保留为线性布局行的背景.

希望有所帮助.

总结

以上是内存溢出为你收集整理的android – API级别10上的ListView行选择器?全部内容,希望文章能够帮你解决android – API级别10上的ListView行选择器?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1124964.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存