我想更改预定义 checkin 的drawable
android.R.layout.simple_list_item_checked
这可能吗?
来自 已检查
和未选中
收件人 选中
和未选中
而且我不想创建自定义列表项。
最佳答案
这是可能的,但只能通过使用带有标准适配器的自定义布局来实现,您可以通过使用自定义布局定义与预定义布局相同的 id 但仅更改您想要的 id 来实现。不幸的是,在这种情况下,android.R.layout.simple_list_item_checked 的源代码默认没有可绘制对象。 ( https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/simple_list_item_checked.xml ) 它使用 checkmark
属性
android:checkMark="?android:attr/textCheckMark"
我不确定您是否可以更改它,但我仍然建议使用带有标准适配器的自定义布局,只需将原始布局与您当前的布局进行比较,并使用可绘制对象而不是复选标记定义所有相同的属性,例如下面的例子:不过这取决于你。
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="new checkbox"
android:background="@drawable/checkbox_background"
android:button="@drawable/checkbox" />
这是根据复选框的状态直接分配保存在@drawable 中的自定义图像的方式。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_focused="true"
android:drawable="@drawable/first" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="@drawable/second" />
<item android:state_checked="false"
android:drawable="@drawable/third" />
<item android:state_checked="true"
android:drawable="@drawable/fourth" />
</selector>
进一步阅读:http://developer.android.com/reference/android/widget/CompoundButton.html#setChecked%28boolean%29
更多信息:http://www.android-ios-tutorials.com/android/custom-android-checkbox-radiobutton/
关于android - 自定义 android.R.layout.simple_list_item_checked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29390798/