<?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".

更多相关文章

  1. Android(安卓)禁止横竖屏切换
  2. android的软键盘的enter键的替换
  3. android根据字体大小设置控件高度
  4. TextView、EditText属性简介
  5. android light
  6. Android中文API(126) —— Message
  7. android 权限设置
  8. 我的android 第三天 - 自定义Toast
  9. Android(安卓)mqtt入门 Android(安卓)studio

随机推荐

  1. 《转》两分钟彻底让你明白Android中onInt
  2. sdcard无法挂载问题
  3. Android文档阅读02—解析Android程序
  4. Android编程 获取网络连接状态 及调用网
  5. Android 使用类加载器原理实现热修复
  6. android登录Web以及登录保持
  7. Android提供的系统服务之--LayoutInflate
  8. android使用高德地图api
  9. cocos2dx--cocos2dx3.1.1android环境编译
  10. Android高手进阶教程(九)----Android Han