step1: 在res下面新建drawable folder,

step2:新增btn_change.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/ic_launcher2"></item>
    <item android:state_enabled="false" android:drawable="@drawable/ic_launcher3"></item> 
    <item android:drawable="@drawable/ic_launcher1"></item>    
</selector>

step3:在相应的drawable-h,l,mdpi下面添加ic_launcher1.png,ic_launcher2.png,ic_launcher3.png

step4:在main.xml中,添加button的background引用

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/btn_change"/>

</LinearLayout>

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
  • 2021-06-04
  • 2021-10-05
  • 2021-06-24
猜你喜欢
  • 2021-08-07
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案