<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_normal" /> <!-- default -->
<item android:state_pressed="true"
android:drawable="@drawable/button_pressed" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/button_focused" /> <!-- focused -->
</selector>
XML file in your project res/drawable/ folder
引用 ImageButton ( android:src attribute).
http://developer.android.com/intl/de/reference/android/widget/ImageButton.html
http://developer.android.com/intl/fr/reference/android/graphics/drawable/StateListDrawable.html
styles 不能代码修改 theme可以动态修改
http://developer.android.com/intl/fr/guide/topics/ui/themes.html
res/drawable/my_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/btn_pressed" />
<item
android:state_pressed="false"
android:drawable="@drawable/btn_normal" />
</selector>
Button如此设置android:background="@drawable/my_button".
本文介绍如何使用Android的StateListDrawable来实现按钮不同状态下的图片显示效果。通过XML文件定义按钮在默认、按下和聚焦状态下的不同样式,适用于Android项目的ImageButton组件。
507

被折叠的 条评论
为什么被折叠?



