ShapeDrawable比较简单,用来定义一个基本几何图形,XML的根元素是<shape.../>

下面定义三个shape资源

my_shape_1.xml

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle" >    <!-- 设置填充颜色 -->    <solid android:color="#fff"/>    <!-- 设置四周的内边距 -->    <padding android:left="7dp"        android:top="7dp"        android:right="7dp"        android:bottom="7dp"/>    <!-- 设置边框 -->    <stroke android:width="3dip" android:color="#ff0"/></shape>

my_shape_2.xml

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle" >    <!-- 定义填充渐变颜色 -->    <gradient         android:startColor="#FFFF0000"        android:endColor="#80FF00FF"        android:angle="45"/>    <!-- 设置内填充 -->    <padding android:left="7dp"        android:top="7dp"        android:right="7dp"        android:bottom="7dp"/>    <!-- 设置圆角矩形 -->    <corners android:radius="8dp"/></shape>

my_shape_3.xml

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="oval" >    <!-- 定义填充渐变颜色 -->    <gradient android:startColor="#ff0"        android:endColor="#00f"        android:angle="45"        android:type="sweep"/>    <!-- 设置内填充 -->    <padding android:left="7dp"        android:top="7dp"        android:right="7dp"        android:bottom="7dp"/>    <!-- 设置圆角矩形 -->    <padding android:left="7dp"        android:top="7dp"        android:right="7dp"        android:bottom="7dp"/>    <!-- 设置圆角矩形 -->    <corners android:radius="8dp"/></shape>

主界面的三个EditBox的背景分别使用上前面定义的三个shape

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <EditText        android:id="@+id/editText1"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:ems="10"         android:background="@drawable/my_shape_1">        <requestFocus />    </EditText>    <EditText        android:id="@+id/editText2"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:ems="10"         android:background="@drawable/my_shape_2"/>    <EditText        android:id="@+id/editText3"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:ems="10"         android:background="@drawable/my_shape_3"/></LinearLayout>

运行效果如下


这样的效果看起来怪怪的,文本框的背景被弄的乱七八糟了


更多相关文章

  1. Android(安卓)自定义Dialog、IOS风格;
  2. Android使用wheelView实现简单类似ios PickerView选择器效果
  3. android 如何隐藏4.0以上系统下面的3按个虚拟按键?
  4. Android之DatePicker和TimePicker实现以及自定义大小
  5. android 输入框 XML 设置于代码设置异同
  6. Android(安卓)抽屉模型实现(Drawer),AndroidX and NavigationView
  7. Android(安卓)使用HTTPClient调用Web请求(查询手机号码区域)
  8. Android(安卓)权限表
  9. android 补间动画TranslateAnimation

随机推荐

  1. Android撬动IT市场的新支点
  2. android中的坐标系以及获取坐标的方法
  3. Android自定义视图二:用Canvas和Paint绘制
  4. Android深度定制化TabLayout:圆角,渐变色,背
  5. android 发送语音功能和ios交互格式aac
  6. Android(安卓)月活跃人数超过10亿用户了,
  7. Android能用Linux打败Linux手机吗?
  8. Android使用Linux mount获取SdCard存储目
  9. 在Android平台上开发移动应用程序(毕业设
  10. Android的深層之美