Android shape、selector的使用

来源:互联网 发布:vgn p17h装linux 编辑:程序博客网 时间:2024/05/16 01:59

首先在res下新建文件夹drawable,然后创建Android XML File

1.四个角圆角、填充白色、描边灰色

<span style="font-size:14px;"><?xml version="1.0" encoding="UTF-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" >    <!-- 填充的颜色 -->    <solid android:color="#ffffff" />    <!-- android:radius 弧形的半径 -->    <corners       android:radius="10dp" />    <!-- 描边 -->    <stroke        android:width="1dp"        android:color="#f8f8f8" /></shape></span>


2.右边不需要描边(那条边不需要描边,只需将right改成相应的边)

<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android" >    <item android:right="-5dp">        <shape>            <solid android:color="#5c5c5c" />            <stroke                android:width="2dp"                android:color="#ff8840" />                   </shape>    </item></layer-list></span>


3.点击更换背景颜色

<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_pressed="false"><shape android:shape="rectangle">            <solid android:color="#ffffff" />            <corners android:radius="8dp" />        </shape></item>    <item android:state_pressed="true"><shape android:shape="rectangle">            <solid android:color="#000000" />            <corners android:radius="8dp" />        </shape></item></selector></span>




1 0
原创粉丝点击