简体   繁体   English

Android。 什么是默认警报对话框宽度

[英]Android. What is default alert dialog width

I use DialogFragment and Inside onCreateDialog return AlertDialog.我使用 DialogFragment 和 Inside onCreateDialog 返回 AlertDialog。 In different devices my dialog width is different.在不同的设备中,我的对话框宽度是不同的。 What is default dialog width?什么是默认对话框宽度? I don't understand what is default dialog window width.我不明白默认对话框 window 宽度是什么。 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我的内容视图宽度是 match_parent

For my dialog I set style @android:style/Theme.Translucent.NoTitleBar对于我的对话框,我设置了样式 @android:style/Theme.Translucent.NoTitleBar

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM