Android 使用shape定义不同控件的的颜色、背景色、边框色

来源:互联网 发布:崩坏3矩阵空间攻略 编辑:程序博客网 时间:2024/05/22 07:58
<?xml version="1.0" encoding="utf-8"?><shape    xmlns:android="http://schemas.android.com/apk/res/android"    android:shape=["rectangle" | "oval" | "line" | "ring"]      //共有4种类型,矩形(默认)/椭圆形/直线形/环形    // 以下4个属性只有当类型为环形时才有效    android:innerRadius="dimension"     //内环半径    android:innerRadiusRatio="float"    //内环半径相对于环的宽度的比例,比如环的宽度为50,比例为2.5,那么内环半径为20    android:thickness="dimension"   //环的厚度    android:thicknessRatio="float"     //环的厚度相对于环的宽度的比例    android:useLevel="boolean">    //如果当做是LevelListDrawable使用时值为true,否则为false.    <corners    //定义圆角        android:radius="dimension"      //全部的圆角半径        android:topLeftRadius="dimension"   //左上角的圆角半径        android:topRightRadius="dimension"  //右上角的圆角半径        android:bottomLeftRadius="dimension"    //左下角的圆角半径        android:bottomRightRadius="dimension" />    //右下角的圆角半径    <gradient   //定义渐变效果        android:type=["linear" | "radial" | "sweep"]    //共有3中渐变类型,线性渐变(默认)/放射渐变/扫描式渐变        android:angle="integer"     //渐变角度,必须为45的倍数,0为从左到右,90为从上到下        android:centerX="float"     //渐变中心X的相当位置,范围为0~1        android:centerY="float"     //渐变中心Y的相当位置,范围为0~1        android:startColor="color"      //渐变开始点的颜色        android:centerColor="color"     //渐变中间点的颜色,在开始与结束点之间        android:endColor="color"    //渐变结束点的颜色        android:gradientRadius="float"  //渐变的半径,只有当渐变类型为radial时才能使用        android:useLevel=["true" | "false"] />  //使用LevelListDrawable时就要设置为true。设为false时才有渐变效果    <padding    //内部边距        android:left="dimension"        android:top="dimension"        android:right="dimension"        android:bottom="dimension" />    <size   //自定义的图形大小        android:width="dimension"        android:height="dimension" />    <solid  //内部填充颜色        android:color="color" />    <stroke     //描边        android:width="dimension"   //描边的宽度        android:color="color"   //描边的颜色        // 以下两个属性设置虚线        android:dashWidth="dimension"   //虚线的宽度,值为0时是实线        android:dashGap="dimension" />      //虚线的间隔</shape>
<!-- 连框颜色值 --><item>         <shape>               <solid android:color="#ff0000" />         </shape>   </item>   <!-- 主体背景颜色值 -->  <item android:bottom="3dp" android:right="3dp">        <shape>              <solid android:color="#ffffff" />             <padding android:bottom="10dp"                  android:left="10dp"                  android:right="10dp"                  android:top="10dp" />       </shape>       </item>  </layer-list> <?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" >    <!-- 圆角 -->    <corners        android:radius="9dp"        android:topLeftRadius="2dp"        android:topRightRadius="2dp"        android:bottomLeftRadius="2dp"        android:bottomRightRadius="2dp"/><!-- 设置圆角半径 -->    <!-- 渐变 -->    <gradient        android:startColor="@android:color/white"        android:centerColor="@android:color/black"        android:endColor="@android:color/black"        android:useLevel="true"        android:angle="45"        android:type="radial"        android:centerX="0"        android:centerY="0"        android:gradientRadius="90"/>    <!-- 间隔 -->    <padding        android:left="2dp"        android:top="2dp"        android:right="2dp"        android:bottom="2dp"/><!-- 各方向的间隔 -->    <!-- 大小 -->    <size        android:width="50dp"        android:height="50dp"/><!-- 宽度和高度 -->    <!-- 填充 -->    <solid        android:color="@android:color/white"/><!-- 填充的颜色 -->    <!-- 描边 -->    <stroke        android:width="2dp"        android:color="@android:color/black"        android:dashWidth="1dp"        android:dashGap="2dp"/></shape><?xml version="1.0" encoding="utf-8"?><shape    xmlns:android="http://schemas.android.com/apk/res/android"    android:shape=["rectangle" | "oval" | "line" | "ring"] >   --- 默认为rectangle    <corners  -- shape=“rectangle”时使用,         android:radius="integer"  -- 半径,会被下边的属性覆盖,默认为1dpandroid:topLeftRadius="integer"         android:topRightRadius="integer"        android:bottomLeftRadius="integer"        android:bottomRightRadius="integer" />    <gradient  -- 渐变        android:angle="integer"        android:centerX="integer"        android:centerY="integer"        android:centerColor="integer"        android:endColor="color"        android:gradientRadius="integer"        android:startColor="color"        android:type=["linear" | "radial" | "sweep"]        android:useLevel=["true" | "false"] />    <padding        android:left="integer"        android:top="integer"        android:right="integer"        android:bottom="integer" />    <size    -- 指定大小,一般用在imageview配合scaleType属性使用。大小一般会适配滴        android:width="integer"        android:height="integer" />    <solid    -- 填充颜色,可是是十六进制颜色。(比如想设置半透明效果,直接使用十六就只就OKandroid:color="color" />    <stroke    -- 指定边框,borderdashWidthdashGap有一个为0dp则为实线        android:width="integer"        android:color="color"        android:dashWidth="integer"    -- 虚线宽度        android:dashGap="integer" />    -- 虚线间隔宽度</shape>
阅读全文
0 0
原创粉丝点击