【发布时间】:2016-11-09 18:25:03
【问题描述】:
我们在列表视图中有一个复选框,其背景图像需要根据列表视图项的内容进行更改,例如 gmail 电子邮件列表视图。
我们现在的方法是使用android:button="@drawable/startcheckbox" 选项设置复选框背景,其中startcheckbox 是可绘制文件夹中的一个xml,其中包含:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="@drawable/star_rate_white_54x54" />
<item android:state_checked="true" android:drawable="@drawable/star_rate_yellow_54x54" />
<item android:drawable="@drawable/star_rate_white_54x54" /> <!-- default state -->
</selector>
我的问题是我们如何从填充列表视图的片段内部更改state_checked="false" 和state_checked="true"。
【问题讨论】:
-
你不能在android上以编程方式更改xml资源文件的内容。
-
使用不同的资源文件
-
见
StateListDrawable文档