Android学习第四天--替换图片
在drawable-hdpi中创建一个xml用来实现图片的替换工作
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/a1" android:state_pressed="true"/> <item android:drawable="@drawable/b1" android:state_pressed="false"/> </selector>
主xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/game" android:gravity="center"> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/button_start" android:id="@+id/imagebutton" android:background="#0000"/> </LinearLayout>
主代码不用进行编辑就可以进行图片切换。