Android编程权威指南(第二版)第二十一章-XML drawable

一般我们需要按钮在不同操作下有不同的动态变化来优化用户的体验

资源文件:res/drawable/button.xml,在这个文件中定义不同状态下button应用不同的样式文件

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:drawable="@drawable/button_pressed"
    android:state_pressed="true"/>

    //在点击状态下用button_beat_box_pressed.xml
  <item android:drawable="@drawable/button_normal" />
</selector>

(button_normal.xml):

  <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid  android:color="@color/dark_blue"/>
  </shape>

(button_pressed.xml):

  <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid  android:color="@color/red"/>
  </shape>

 

posted @ 2017-04-16 01:00  HeLing_CC  阅读(96)  评论(0)    收藏  举报