ShapeDrawable
ShapeDrawable用于定义一个基本几何图形(正方形,圆形,线条),定义ShapeDrawable的xml文件的根元素<shape .../>元素,该元素可制定如下属性:
1.android:shape = ["rechangle" | "oval" | "line" | "ring" ]
my_shape_1.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape = "rectangle">
<!-- 设置填充颜色 -->
<soild android:color="#fff"/>
<!-- 设置四周的内边距 -->
<padding android:left="7dp"/>
<padding android:top="7dp"/>
<padding android:right="7dp"/>
<padding 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">
<!-- 设置填充颜色 -->
<soild android:color="#fff"/>
<!-- 设置四周的内边距 -->
<padding android:left="7dp"/>
<padding android:top="7dp"/>
<padding android:right="7dp"/>
<padding android:bottom="7dp"/>
<stroke android:width="3dip" android:color="#ff0"/>
</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:right = "7dp"
android:top = "7dp"
android:bottom = "7dp"
/>
<corrners android:radius = "8dp"/>
</shape>
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.sharpedrawable.MainActivity" >
<EditText
android:id="@+id/editText1"
android:background="@drawable/my_shape_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="29dp"
android:layout_marginTop="33dp"
android:ems="10" />
<EditText
android:id="@+id/editText2"
android:background="@drawable/my_shape_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/editText1"
android:layout_marginTop="30dp"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText3"
android:background="@drawable/my_shape_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText2"
android:layout_below="@+id/editText2"
android:layout_marginTop="31dp"
android:ems="10" />
</RelativeLayout>
使用activity加载和显示上面的界面布局