您的位置:首页 > 移动开发 > Android开发

Android shape、selector的使用

2016-04-27 15:08 274 查看
首先在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>



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: