<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/search_pressed" android:state_enabled="true" android:state_pressed="true" />
    <item android:drawable="@drawable/search_normal" android:state_enabled="true" android:state_pressed="false" />
    <item android:drawable="@drawable/search_disable" />
</selector>

特殊场景需要ImageView 默认情况下无背景,满足条件后显示背景,同事点击要有压下效果,

layout中设置 ImageView

android:enabled="false"
无效,由于ImageView默认是enabled状态,所以显示出背景
解决办法:
在代码中初始化设置
mBinding.btnSearch.isEnabled = false
生效
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐