有没有办法向ImageView添加按下状态?我有一个图像,我点击了一个点击监听器,当我按下它时,我想更改为imageview src一秒钟来模仿按钮或列表视图项的按下状态.
我可以在src属性中添加选择器xml吗?
弄清楚了.您可以将选择器xml添加到ImageView的src属性中.
在我的例子中,我在drawables中创建了“addbuttonbg.xml”:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/quickaddbutton" />
<item android:state_pressed="true"
android:drawable="@drawable/quickaddbutton_click" />
<item android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/quickaddbutton" />
</selector>
然后将您的imageview src设置为@ drawable / addbuttonbg
解决方法:
是的,您可以添加选择器以获得印刷效果
样品:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/postbutton_press" android:state_pressed="true"/>
<item android:drawable="@drawable/postbutton_press" android:state_focused="true"/>
<item android:drawable="@drawable/postbutton_normal"/>
</selector>
到ImageView的android:src =“@ drawable / post_btn_click”属性或android:background =“@ drawable / post_btn_click”到按钮属性
post_btn_click – > selector drawable的文件名