更新时间:2023-01-05 14:29:50
在drawable中创建xml,例如dialog_bg.xml
Create a xml in drawable , say dialog_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="@color/white"/>
<corners
android:radius="30dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
将其设置为布局xml中的背景
set it as the background in your layout xml
android:background="@drawable/dialog_bg"
将对话框的根视图的背景设置为透明,因为Android会将对话框布局放置在根视图中,该视图隐藏了自定义布局中的各个角.
Set the background of the dialog's root view to transparent, because Android puts your dialog layout within a root view that hides the corners in your custom layout.
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));