0
点赞
收藏
分享

微信扫一扫

按钮的多样话 selector的使用

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


举报

相关推荐

0 条评论