第一步:

在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为指定控件,可以是任意类型)

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐