package com.test.shapedrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
/**
* ShapeDrawable 用于定义一个基本的几何图形(如矩形,圆形,线条等)
*/
public class ShapeDrawableActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shape_drawable);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical"
tools:context="com.test.shapedrawable.ShapeDrawableActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/my_shape_1"
/>
<EditText
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/my_shape_2"
/>
<EditText
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/my_shape_3"
/>
</LinearLayout>
shape 资源文件
<?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:bottom="7dp" android:left="7dp"
android:top="7dp" android:right="7dp" />
<stroke android:color="#ff0" android:width="3dp" android:dashWidth="3dp"
android:dashGap="3dp"
/>
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="45"
android:centerColor="#80ff00ff"
android:startColor="#ffff0000"/>
<padding
android:bottom="7dp"
android:left="7dp"
android:right="7dp"
android:top="7dp"/>
<corners android:radius="8dp"/>
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<gradient
android:angle="45"
android:endColor="#00f"
android:startColor="#ff0"
android:type="sweep"/>
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp"/>
<corners android:radius="8dp"/>
</shape>