我有一个带有 drawableEnd 的 EditText。我想在按下时更改此可绘制对象。我已经创建了选择器,但现在看不到任何图像。甚至可以这样做,还是我做错了什么?
布局
<EditText
android:drawableEnd="@drawable/selector"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
选择器
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/image_on"
android:state_enabled="true"
android:state_pressed="true"/>
<item
android:drawable="@drawable/image_off"
android:state_enabled="true"/>
</selector>
最佳答案
您的选择器似乎有误,您必须在一项中声明一个语句。并且您为 state_enabled="true"设置了两个项目。它必须是:
<item
android:drawable="@drawable/pressed_image"
android:state_pressed="true"/>
<item
android:drawable="@drawable/image_on"
android:state_enabled="true"/>
<item
android:drawable="@drawable/image_off"
android:state_enabled="false"/>
而且,很长一段时间以来,我发现语句的顺序也很重要。调用错误的命令有时会导致没有结果....
关于android - EditText 中可绘制对象的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35057436/