1. 在drawable 下新建 shape.xml 文件
<?xml version="1.0" encoding="UTF-8"?>  <shape xmlns:android="http://schemas.android.com/apk/res/android"      android:shape="rectangle" >      <!-- 填充的颜色 -->    <solid android:color="#FFFFFF" />    <!-- 设置矩形的四个角为弧形 -->    <!-- android:radius 弧形的半径 -->    <corners android:radius="7dip" /> </shape>


android:radius为角的弧度,值越大角越圆。

我们还可以把四个角设定成不同的角度,方法为:
<corners        android:bottomLeftRadius="20dp"        android:bottomRightRadius="0dp"        android:topLeftRadius="1dp"        android:topRightRadius="20dp" />


2.设置引用

android:background="@drawable/shape"

EditText 其它属性

android:hint="请输入用户名" <!-- 设置提示文本 -->
android:drawableLeft="@drawable/ic_launcher" <!-- 设置文本框左边小图标 -->

<?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>


填充:设置填充的颜色

间隔:设置四个方向上的间隔

大小:设置大小

圆角:同时设置五个属性,则Radius属性无效

android:Radius="20dp" 设置四个角的半径

android:topLeftRadius="20dp" 设置左上角的半径
android:topRightRadius="20dp" 设置右上角的半径
android:bottomLeftRadius="20dp" 设置右下角的半径
android:bottomRightRadius="20dp" 设置左下角的半径

描边:dashWidth和dashGap属性,只要其中一个设置为0dp,则边框为实现边框

android:width="20dp" 设置边边的宽度
android:color="@android:color/black" 设置边边的颜色
android:dashWidth="2dp" 设置虚线的宽度
android:dashGap="20dp" 设置虚线的间隔宽度

渐变:当设置填充颜色后,无渐变效果。angle的值必须是45的倍数(包括0),仅在type="linear"有效,不然会报错。android:useLevel 这个属性不知道有什么用


更多相关文章

  1. Android属性gravity与layout_gravity的区
  2. View的xml的属性作用大剖析
  3. 关于相对布局RelativeLayout的各种属性介绍
  4. Android中TextView:的ellipsize属性
  5. Android 众多的布局属性详解
  6. android:属性 layout_alignParentRight android:paddingRight
  7. android 组件属性描述

随机推荐

  1. android layout 按比例布局
  2. Android实现流量统计和网速监控悬浮窗
  3. No resource found that matches the giv
  4. Android—Animation
  5. android Recorder流程
  6. android setTag (int key, Object tag)抛
  7. Android图片轮播
  8. Android遍历获取指定目录的文件
  9. ListView与其中的Button,EditText等Widge
  10. 在ubuntu10.10上安装android sdk