0
<?xml version="1.0" encoding="utf-8"?>
<layout 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">

    <data></data>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white">
        
        <View
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:background="@color/my_color"
            app:layout_constraintBottom_toBottomOf="parent"/>
    </androidx.constraintlayout.widget.ConstraintLayout>
<layout>

Left image is from XML, but after launching the application, the dialog shows incorrectly. I guess this acts like the ConstraintLayout's height is wrap_parent and can't detect the bottom.

How can I fix this?

enter image description here

c-an
  • 3,543
  • 5
  • 35
  • 82
  • try [This thread](https://stackoverflow.com/questions/2306503/how-to-make-an-alert-dialog-fill-90-of-screen-size). If you are using Custom View already better Go for `DialogFragment` or `Dialog` . `AlertDialog` is a special purpose dialog suitable for only alerts. you can same thing with `AlertDialog` because its a dialog indeed . – ADM Dec 10 '21 at 06:07
  • are you using `requireContext()` for your `AlertDialog.Builder` context or just using `null`? – Afshin Dec 10 '21 at 07:43

2 Answers2

0

on YourDialog class, you can set dialog width and height,like this.

    override fun onStart() {
        super.onStart()
        dialog?.let { dia ->
        dia.window?.let { win ->
            val attributes = win.attributes
            attributes.width = ViewGroup.LayoutParams.MATCH_PARENT
            attributes.height = ViewGroup.LayoutParams.MATCH_PARENT
            win.attributes = attributes
        }
    }
}
Mr.Bendan
  • 3
  • 2
0

Your View is not a dialog. Use DialogFragment and set this

val params = window.attributes
params?.width = ViewGroup.LayoutParams.MATCH_PARENT
params?.height = ViewGroup.LayoutParams.WRAP_CONTENT
params?.gravity = Gravity.BOTTOM
window.attributes = params
Krahmal
  • 195
  • 13