Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 如何防止ListItem中的Button获得突出显示大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
所以我有自定义列表项,带有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"
            style="@style/PriMaryText" />

        <TextView
            android:id="@+id/txtSub"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
            style="@style/SecondaryText" />
    </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://scheR_899_11845@as.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获得突出显示所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。