记录一下xml设置各种背景,不然经常翻之前的代码,哈哈
1.设置圆角背景
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#fcfcfc" /> 背景颜色
<corners android:radius="5dp"/> 圆角大小
//边框颜色和宽度,可选
<!--<stroke android:width="0.5dp" android:color="@color/colorPrimary" />-->
</shape>
2.设置圆形背景
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="false">
<solid android:color="@color/white"/> 背景颜色
<stroke android:width="1.5dp" android:color="#ff2003" /> 边框可选
<size //大小不必要
android:width="15dp"
android:height="15dp" />
</shape>
3.背景上/下/左/右带边框
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- This is the main color -->
<item>
<shape>
<solid android:color="@color/color_line"/>//边框颜色
</shape>
</item>
//根据需要自己设置显示边框的未知 top left right bottom
<item android:bottom="0.8dp" android:top="0.8dp">
<shape>
<solid android:color="@color/white" />//填充颜色
</shape>
</item>
</layer-list>
4.边框设置虚线
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#f5f6f7" /> //填充颜色
<corners android:radius="4dp"/> //圆角大小
<stroke android:width="1dp" android:color="#ccc" //边框宽度和颜色
android:dashGap="3dp" //间隔距离
android:dashWidth="5dp"/>//虚线的长度
</shape>
5.设置渐变色-圆角
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:endColor="#35a3ff" //渐变结束颜色
android:startColor="#6bd7ff" />//渐变开始颜色
<corners android:radius="50dp" /> // 圆角大小
</shape>
6.设置渐变色-圆形
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="false">
//开始结束颜色
<gradient android:startColor="#6bd7ff" android:endColor="#35a3ff" />
//边框可选
<!-- <stroke android:width="1dip" android:color="#000000" />-->
<size
android:width="15dp"
android:height="15dp" />
</shape>
7.背景上/下/左/右带圆角
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
//填充颜色
<solid android:color="@color/white" />
//设置圆角位置
<corners android:topRightRadius="5dp" android:bottomRightRadius="5dp"/>
//边框颜色可宽度
<!--<stroke android:width="0.5dp" android:color="@color/lineBGColor"/>-->
</shape>
8.设置文字选中颜色
//TextView 设置textColor属性
android:textColor="@drawable/color_text"
//color_text.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#40464f" android:state_checked="true"></item>
<item android:color="@color/white" android:state_checked="false"></item>
</selector>