android - 自定义 android.R.layout.simple_list_item_checked

标签 android listview

我想更改预定义 checkin 的drawable

android.R.layout.simple_list_item_checked 这可能吗?

来自 已检查 enter image description here

和未选中 enter image description here

收件人 选中enter image description here

和未选中 enter image description here

而且我不想创建自定义列表项。

最佳答案

这是可能的,但只能通过使用带有标准适配器的自定义布局来实现,您可以通过使用自定义布局定义与预定义布局相同的 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/

相关文章:

c# - 我怎样才能解决这个糟糕的 WPF ListView SelectedItems 性能问题?

listview - 如何在flutter中使我的文本与listview.builder一起滚动

android - 操作栏仅在搜索 View 旁边显示一项

android - 没有 Google Play 服务的 Google Plus 登录

android - flatMap just 与 map 返回参数之间的 Rxjava 区别

c# - ListView 图像只是不显示。为什么(羞愧地低下头,我不得不问)

java - CAB 上的 Android 持久 gridview 选择器

java - Android Studio 在版本控制中使用 Git : gradle-wrapper. jar

android - 无法将android项目导入Eclipse

Android:onItemClick 仅返回第一个选定的项目