android中AlertDialog设置圆角

参考网址:https://blog.csdn.net/qq_33224517/article/details/53421307

说明:在AlertDialog自定义布局的时候,想要一个圆角效果,但是给xml设置圆角后,AlertDialog并不是显示的圆角,只有自定义的布局是圆角样式,AlertDialog会显示出一个白色四方的背景

AlertDialog alertDialog = new AlertDialog.Builder(this).create();
Window window = alertDialog.getWindow(); 
//这一句消除白块 
window.setBackgroundDrawable(new BitmapDrawable());
//自定义的xml
window.setContentView(R.layout.mydialog);
alertDialog.show();
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/mywhite" /><!-- 背景色 -->
    <corners android:topLeftRadius="15dp"
        android:topRightRadius="15dp"
        android:bottomRightRadius="15dp"
        android:bottomLeftRadius="15dp"/><!-- 四个圆角的圆角大小 -->
    <stroke android:width="1dp" android:color="@color/mywhite" /><!-- 边框色 -->
</shape>

猜你喜欢

转载自blog.csdn.net/aidou1314/article/details/89552685