分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
使用XML实现按钮改变焦点设置背景图,获得焦点时,获得焦点并按下,失去焦点时,默认时...
新建res/drawable/button.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/focusimage"/><!-- 获得焦点并按下 --><itemandroid:state_focused="true"android:state_pressed="true"android:drawable="@drawable/clickimage"/><!-- 失去焦点时 --><itemandroid:state_focused="false"android:state_pressed="true"android:drawable="@drawable/clickimage"/><!-- 默认时 --><item android:drawable="@drawable/normal"/></selector>
main.xml
<?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" > <Button android:layout_marginTop="20dp" android:id="@+id/button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="不同状态的Button" android:background="@drawable/button"/></LinearLayout>