@Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));//1.必须设置dialog的window背景为透明颜色,不然圆角无效或者是系统默认的颜色 return inflater.inflate(R.layout.dialog_pay_sure_alert, container); }
<FrameLayout //2.必须布局文件最外层包裹一层,这样才能显示指定的对话框大小,比如这里的 380dp x 205dp xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="380dp" android:layout_height="205dp" android:paddingBottom="21dp" android:paddingLeft="16dp" android:paddingRight="16dp" //最好设置一些padding,有时候可能因为没有padding,圆角被子控件覆盖而无效 android:background="@drawable/bg_promo_input_dialog"> </android.support.constraint.ConstraintLayout></FrameLayout>
<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="@color/white"/> <corners android:radius="20dp"/> </shape> </item></layer-list>
原文地址:https://www.cnblogs.com/yongfengnice/p/10362827.html
时间: 2024-10-12 02:26:27