问题描述
- android,Listview中item点击变色冲突
-
我想要像微博一样,当点击评论、转发、赞3个按钮的时候,只有按钮变色。
点击其他地方时,整个item都变色。然后我为最外层的布局和“评论、点赞、转发”3个按钮的布局都设置了selector,但结果是无论点击item的哪个地方,都是整个布局都变色。怎么修改都不行,不知是哪里出了问题
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@color/gray"></item> <item android:drawable="@color/white"></item> </selector>
解决方案
在你适配器中的xml加上android:descendantFocusability="blocksDescendants"这句
解决方案二:
android:descendantFocusability
Defines the relationship between the ViewGroup and its descendants when looking for a View to take focus.
Must be one of the following constant values.
该属性是当一个为view获取焦点时,定义viewGroup和其子控件两者之间的关系。
属性的值有三种:
beforeDescendants:viewgroup会优先其子类控件而获取到焦点
afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点
blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点
时间: 2024-08-26 14:51:49