一、效果展示
二、实现步骤
首先默认边框什么也不用改,无边框是通过在布局文件xml中,将android:background属性设为@null。
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="这是默认边框"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:hint="这是没有边框"/>
圆角边框则是需要先设计一个圆角矩形,首先创建文件rounded_rectangle。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:color="#aaaaaa" android:width="1dp" android:dashGap="4dp" android:dashWidth="10dp" />
<corners android:radius="5dp" />
<padding android:bottom="5dp" //设置内边距的原因是,这样边框内的字体就可以和边框保持一定的距离,不至于太挤
android:left="5dp"
android:right="5dp"
android:top="5dp"/>
</shape>
最后简单的设计布局文件,引用设计的圆角矩形:
<EditText
android:layout_width="match_parent"
android:layout_marginTop="5dp"
android:layout_height="wrap_content"
android:background="@drawable/rounded_rectangle"
android:hint="这个是圆角边框"/>