GridView 子级不显示焦点
在 Android 应用程序中,我有一个 GridView 保存由适配器创建的 TextView。在这些 TextView 中,我添加了一个具有三种状态(按下、选择和默认)的图标。 我使用 android:listSelector="#00000000"
删除了 GridView 的默认选择器,我希望显示图标的选定状态。但是,尽管按下状态有效(即当按下 TextView 时,会显示图标的按下版本),但选择的状态却不起作用。
我已经尝试过这些技巧(在网络上的不同地方找到),但它也不起作用:
设置
android:descendantFocusability="afterDescendants"
或
android:drawSelectorOnTop="true"
或(在 TextView 中)
android:duplicateParentState="true" />
如果我将 TextView 设置为可聚焦,它就会独立于 GridView 获得焦点(即,单击它不会调用 GridView onClick 方法...
)图标在 xml 文件中定义如下:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/ic_flag_bg_pressed"/>
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/ic_flag_bg_pressed"/>
<item android:state_focused="true"
android:drawable="@drawable/ic_flag_bg_selected"/>
<item android:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/ic_flag_bg_default"/>
</selector>
有没有办法告诉 GridView 将焦点状态传递给其子级?
In an android app, I have a GridView holding TextView created by an adapter. In those TextView I add an icon which has three states (pressed, selected and default.)
I removed the default selector of the GridView with android:listSelector="#00000000"
and I would like the selected state of the icon to display instead. But although the pressed state works (ie when the TextView is pressed, the pressed version of the icons is shown) the seleted doesn't.
I've tried those tricks (found at different places on the web) but it didn't work either:
setting
android:descendantFocusability="afterDescendants"
or
android:drawSelectorOnTop="true"
or (in the TextViews)
android:duplicateParentState="true" />
And if I set the TextView to be focusable, it gets focus independently of the GridView (ie, clicking on it doesn't call the GridView onClick method...)
The icon is defined in a xml file like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/ic_flag_bg_pressed"/>
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/ic_flag_bg_pressed"/>
<item android:state_focused="true"
android:drawable="@drawable/ic_flag_bg_selected"/>
<item android:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/ic_flag_bg_default"/>
</selector>
Is there a way to tell the GridView to pass the focused state to its children ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也被困在这个问题上了。另一种看起来不错的方法是使用边框样式选择器并将其绘制在顶部。
Got stuck on this as well. An alternate approach that can look okay is to use a border style selector and draw it on top.