android – 如何防止ListItem中的Button获得突出显示

android – 如何防止ListItem中的Button获得突出显示,第1张

概述所以我有自定义列表项,带有ListView按钮.按下时,按钮显示交替可绘制以向用户显示反馈.但是,当我点击该行时,每个按钮都显示按下状态,就像我点击它们一样. 如何让按钮显示其原始状态而不是state_pressed? 布局/列表项目: <LinearLayout android:layout_width="0dp" android:layout_height="match_par 所以我有自定义列表项,带有ListVIEw按钮.按下时,按钮显示交替可绘制以向用户显示反馈.但是,当我点击该行时,每个按钮都显示按下状态,就像我点击它们一样.

如何让按钮显示其原始状态而不是state_pressed?

布局/列表项目:

<linearLayout    androID:layout_wIDth="0dp"    androID:layout_height="match_parent"    androID:layout_weight="1"    androID:orIEntation="horizontal"    androID:paddingBottom="10dp"    androID:paddingtop="10dp"    androID:descendantFocusability="blocksDescendants" >    <linearLayout        androID:layout_wIDth="0dp"        androID:layout_height="match_parent"        androID:layout_weight="1"        androID:orIEntation="vertical"        androID:paddingleft="10dp"        androID:paddingRight="10dp"        androID:gravity="center_vertical|left" >        <TextVIEw            androID:ID="@+ID/txtMain"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:singleline="true"            androID:textAppearance="?androID:attr/textAppearanceLarge"             />        <TextVIEw            androID:ID="@+ID/txtSub"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:singleline="true"            androID:textAppearance="?androID:attr/textAppearanceLarge"             />    </linearLayout>    <Imagebutton        androID:ID="@+ID/imbResponse"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:background="@null"        androID:focusable="false"        androID:duplicateParentState="false"        androID:src="@drawable/response_btn"         androID:contentDescription="@string/response"        androID:layout_marginleft="10dp"        androID:layout_margintop="5dp"        androID:layout_marginRight="10dp"        androID:layout_marginBottom="5dp" /></linearLayout>

绘制/ response_btn.xml:

<?xml version="1.0" enCoding="utf-8"?><selector xmlns:androID="http://schemas.androID.com/apk/res/androID" >    <item androID:state_focused="true" androID:drawable="@drawable/res_m" />    <item androID:state_pressed="true" androID:drawable="@drawable/res_m" />    <item androID:state_focused="false" androID:state_pressed="false" androID:drawable="@drawable/res_alt_m" /></selector>

我试图删除state_focused和state_pressed,state_focused.似乎该按钮从其父级获取state_pressed.

解决方法 我发现将androID:clickable =“true”设置为父视图将阻止更改子视图状态.

见this answer.

总结

以上是内存溢出为你收集整理的android – 如何防止ListItem中的Button获得突出显示全部内容,希望文章能够帮你解决android – 如何防止ListItem中的Button获得突出显示所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1130263.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存