Scope:
- 使用重写的ArrayAdapter;
- 使用选择器;
- 使用 isEnabled 禁用项目。
Aim:
- 禁用某些列表项并通过选择器加载禁用状态视图。
Problem:
- 一切正常(自定义视图、未聚焦、聚焦和按下状态的选择器),但禁用的项目不使用禁用状态的选择器。
调查中:当我使用 isEnabled 禁用列表视图层次结构查看器中的某些项目时,显示禁用的项目不可聚焦、不可单击,但(!)已启用。
Is it a bug或者缺少什么?
附:实际上,文档说 isEnabled 不会对列表项执行 setEnabled(false) ,它使其成为分隔符(?)对象。
P.P.S 我还尝试使用 if 语句将我的视图(在 getView 中)设置为 isEnabled(false)。但它只适用于重点项目?
我的选择器看起来像:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Disabled -->
<item
android:state_enabled="false"
android:textColor="@color/greyDark"
android:drawable="@drawable/list_item_disabled" />
<!-- Pressed -->
<item
android:state_enabled="true"
android:state_pressed="true"
android:textColor="@android:color/white"
android:drawable="@drawable/list_item_pressed" />
<!-- Focused -->
<item
android:state_enabled="true"
android:state_focused="true"
android:textColor="@android:color/white"
android:drawable="@drawable/list_item_focused" />
<!-- Default -->
<item
android:state_enabled="true"
android:drawable="@drawable/list_item_unfocused" />
</selector>
适配器中的函数 isEnabled() 只会使项目不可聚焦和不可点击。
你需要打电话view.setEnabled()
在......的最后adapter.getView()
使您的选择器发挥作用。
此外,对于父视图将启用状态传递给其后代,您需要指定属性android:duplicateParentState="true"
到 xml 文件中的子视图。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)