使用自定dialog继承Dialog,设置根布局固定宽高时无效,只会显示子view的实际大小,就是子view显示多大,dialog就显示多大,解决方法就是在根布局添加一个子view设置它的宽高,用来撑起dialog的大小
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="@dimen/dp_293"
android:layout_height="@dimen/dp_288" //这里设置的宽高无效
android:background="@drawable/login_erro"
tools:ignore="MissingDefaultResource">
<View
android:layout_width="@dimen/dp_293"
android:layout_height="@dimen/dp_288"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>