我在我的布局中使用 ListView
是这样的:
<ListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:layout_height="match_parent"
android:layout_weight="0.7"
android:layout_marginTop="5dp"
android:orientation="vertical"
android:layout_centerInParent="true"
android:divider="@color/dark_grey"
android:drawSelectorOnTop="false"
android:focusable="true"
android:layout_marginBottom="55dp"
android:cacheColorHint="#00000000"
android:listSelector="@color/light_grey"
android:dividerHeight="1px" />
选择器效果很好,但如何禁用选择器?
我试过:
listView.clearChoices();
listView.setSelected();
listView.setSelector();
...
还有一些东西,但没有任何效果。有什么想法可以让我选择的项目恢复正常吗?不可能那么复杂,对吧?
编辑: 我需要一个程序化的解决方案!
原文由 Ron 发布,翻译遵循 CC BY-SA 4.0 许可协议
在
ListView
之后的 --- 调用requestLayout()
clearChoices()
。它会起作用。