矩形文本框:
/ShapeDrawableTest/res/drawable-hdpi/my_shape_1.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#fff"/>
<padding android:left="7dp"
android:right="7dp"
android:top="7dp"
android:bottom="7dp"/>
<stroke android:width="3dip" android:color="#ff0"/>
</shape>
带有填充渐变颜色矩形文本框:
/ShapeDrawableTest/res/drawable-hdpi/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>
椭圆形的文本框:
/ShapeDrawableTest/res/drawable-hdpi/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"/>
<corners android:radius="8dp"/>
</shape>
/ShapeDrawableTest/res/layout/activity_main.xml
这样引用:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/my_shape_1" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/my_shape_2" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/my_shape_3" />
</LinearLayout>