给EditText设置边框

布局文件中加入background属性:

        <EditText
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:inputType="phone"
            android:text=""
            android:id="@android:id/edit"
            android:background="@drawable/edit_bg"/>

然后在drawable文件夹下新建一个名为edit_bg的xml,里面内容为:

<?xml version="1.0" encoding="utf-8"?>
<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
            <solid
                android:color="#EFEFEF"/>
            <corners
                android:radius="3dip"
                />
            <stroke
                android:width="0.5px"
                android:color="#505050"/>
        </shape>
    </item>
</layer-list>

原文地址:https://www.cnblogs.com/johnsonwei/p/5785055.html