第一步:
在res下新建一个resource file,选择drawable、shape
第二步:
自定义设计,corners为设计圆角,stroke设计边框
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android" tools:ignore="ExtraText">
<corners
android:radius="10dp">
</corners>
<stroke
android:color="@color/purple_200"
android:width="2dp">
</stroke>
</shape>
效果如图
第三步:
方法一:在xml的指定控件选择
android:background = "@drawable/underline"
方法二:在java文件中对指定控件使用
new_class.setBackground(getResources().getDrawable(R.drawable.underline));
其中(new_class为指定控件,可以是任意类型)