例一:
<?xml version="1.0" encoding="UTF-8"?>-<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white"/>
<stroke android:color="#E5E5E5" android:width="1dp"/>
<corners android:radius="5dp"/>
</shape>
例二:
<?xml version="1.0" encoding="UTF-8"?>
-<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffffff"/>
<corners android:topLeftRadius="8dp" android:bottomLeftRadius="8dp"/>
<stroke android:color="#ff02cecd" android:width="1dp"/>
</shape>
总结:用drawable文件写shape时注意它的几个属性,solid属性用来描述形状主体内容,corners用来描述形状的左上、右上、左下、右下四个角的弧度,stroke用来描述形状的边框样式。当属性未描述时则使用默认样式。
总共shape属性有如下几种: <corners> 定义圆角 <gradient> 定义颜色渐变,从左下角到或上角 <padding> 定义控件内容到边框的距离 <stroke> 定义边线<solid> 定义填充 <size> 定义大小。