首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

selector的运用

2012-08-25 
selector的使用使用selector可以实现在XML中动态改变布局:(1)在res/drawable下定义一个文件advancedbutton

selector的使用
使用selector可以实现在XML中动态改变布局:
(1)在res/drawable下定义一个文件advancedbutton.xml

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:state_focused="true" android:state_pressed="false"android:drawable="@drawable/onfocusimage" /><item android:state_focused="true" android:state_pressed="true"android:drawable="@drawable/clickimage" /><item android:state_focused="false" android:state_pressed="true"android:drawable="@drawable/clickimage" /><item android:drawable="@drawable/lostfocusimage" /></selector>

(2)在布局文件main.xml中使用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:background="#FF25CCDD"><ImageButton android:id="@+id/image_Button"android:layout_width="fill_parent" android:layout_height="wrap_content"android:background="@drawable/advancedbutton"/><Button android:text="Button01" android:id="@+id/Button01"android:layout_width="wrap_content" android:layout_height="wrap_content"></Button></LinearLayout>具体示例见附件

热点排行