selector的例子

例子1

文件名:sl_rounded_rectangle_button_picture.xml

 

文件内容:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/ic_btn_click" android:state_pressed="true"/>
<item android:drawable="@drawable/ic_btn_normal" android:state_enabled="false"/>
<item android:drawable="@drawable/ic_btn_normal"/>

</selector>



例子2
主文件:sl_rounded_rectangle_button.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/bg_rounded_rectangle_button_p" android:state_pressed="true"/>
<item android:drawable="@drawable/bg_rounded_rectangle_button_en" android:state_enabled="false"/>
<item android:drawable="@drawable/bg_rounded_rectangle_button_n"/>

</selector>

例子2 辅助文件
bg_rounded_rectangle_button_p
.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<solid android:color="@color/common_btn_press_color" />

<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />

</shape>


例子2 辅助文件
bg_rounded_rectangle_button_en.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<solid android:color="@color/common_btn_normal_color" />

<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />

</shape>

例子2 辅助文件
bg_rounded_rectangle_button_n.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<solid android:color="@color/common_btn_normal_color" />

<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />

</shape>

 
 



 
posted @ 2017-04-24 11:02  杨斌_济南  阅读(354)  评论(0编辑  收藏  举报