读书人

android中button经过XML来改变它背景图

发布时间: 2012-08-07 14:54:48 作者: rapoo

android中button通过XML来改变它背景图片

使用XML实现按钮改变焦点设置背景图,获得焦点时,获得焦点并按下,失去焦点时,默认时...

?

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"><!-- 获得焦点时 --><itemandroid:state_focused="true"android:state_pressed="false"android:drawable="@drawable/onfocusimage2"/><!-- 获得焦点并按下 --><itemandroid:state_focused="true"android:state_pressed="true"android:drawable="@drawable/clickimage2"/><!-- 失去焦点时 --><itemandroid:state_focused="false"android:state_pressed="true"android:drawable="@drawable/clickimage2"/><!-- 默认时 --><item android:drawable="@drawable/defaultimage2"/></selector>

?

?

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:id="@+id/settingsLayoutId"    android:gravity="center"    >   <!--这个android:background就读取自己定义的XML文件-->     <Button        android:background="@anim/imgbutton"        android:text="@string/app_pic"        android:id="@+id/imagesBut"        style="@style/settingsBut"        /> </LinearLayout>

? 完成!

读书人网 >XML SOAP

热点推荐