下面来看一下实现方法:
1、先在drawable文件夹下创建一个myedittext.xml文件,文件代码如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!--solid里是背景的填充颜色,transparent是透明-->
<solid android:color="@android:color/transparent"/>
<!--
corners里的属性,是四个边角拐角的大小
topLeftRadius:左上角
topRightRadius:右上角
bottomRightRadius:右下角
bottomLeftRadius:左下角
-->
<corners
android:topLeftRadius="100dp"
android:topRightRadius="10dp"
android:bottomRightRadius="100dp"
android:bottomLeftRadius="10dp"
/>
<!--stroke里是边框的宽度和颜色-->
<stroke
android:width="1dp"
android:color="@android:color/holo_blue_light"
/>
</shape>
2、二是在布局文件里调用这个资源:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
tools:context="com.example.test.MainActivity">
<!--在background里设置就好-->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/myedittext"
/>
</RelativeLayout>
3、最后来看一下效果