Android. What is default alert dialog width

223 Views Asked by At

I use DialogFragment and Inside onCreateDialog return AlertDialog. In different devices my dialog width is different. What is default dialog width ? I don't understand what is default dialog window width. I didn't find any properties that define the width of the dialog. I don't need to change the dialog width, I just want to know what the default dialog width is.

Also, I noticed that regardless of the content of the dialog, the width always stays fixed.

My content view width is match_parent

For my dialog I set style @android:style/Theme.Translucent.NoTitleBar

1

There are 1 best solutions below

0
Дмитрий Техников On

Usually the size of the dialog depends on the content.

If you want to change size of the dialog use:

  val params = dialog?.window?.attributes

  // match parent (all width of screen)
  params?.width = FrameLayout.LayoutParams.MATCH_PARENT

  // fixed height
  params?.height = 32.dp(requireContext())

  dialog?.window?.attributes = params