Android 全屏警报对话框

标签 android android-alertdialog material-components-android

我正在尝试在 Android 应用程序中创建全屏对话框,但无法将其扩展到状态栏。您可以在下图中看到灰色状态栏。

编辑1: 这似乎是与安装的操作系统有关的问题,而不是与 Android 组件有关的问题,因为我仅在某些设备上遇到此问题。

enter image description here

AlertDialog 创建:

    val builder = MaterialAlertDialogBuilder(this, R.style.FullscreenDialogStyle)
    val binding = DialogSuccessBinding.inflate(layoutInflater)
    binding.SuccessDialogMessage.text = getString(R.string.AddGuestCard_Success)
    builder.setView(binding.root)
    builder.background = ColorDrawable(getColor(R.color.primary))
    builder.setBackgroundInsetBottom(0)
    builder.setBackgroundInsetTop(0)
    builder.setBackgroundInsetStart(0)
    builder.setBackgroundInsetEnd(0)
    builder.show()

AlertDialog 样式:

<style name="FullscreenDialogStyle" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@color/primary</item>
    <item name="android:navigationBarColor">@color/primary</item>
    <item name="android:statusBarColor">@color/primary</item>
    <item name="android:layout_gravity">center</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">false</item>
</style>

最佳答案

yes, it has camera notch

要通过覆盖相机凹口区域(切口显示区域)使对话框全屏显示,您需要将显示切口显式调整为 shortEdgesalways使用android:windowLayoutInDisplayCutoutMode对话框主题中的属性:

<style name="FullscreenDialogStyle" parent="Theme.AppCompat.NoActionBar">
    ....
    <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>

check documentation此处进行进一步研究;.

关于Android 全屏警报对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72635367/

相关文章:

Android DefaultHttpClient 接受 SSL session 帮助的所有证书

android - 如何定义自定义应用程序主题来指定 Android 布局的默认背景?

react-native - React Native 中不显示警报按钮

java - Android 无法解析 AlertDialog.setPositiveButton()

android - 如何更改Android Material TextInputLayout组件的非 Activity 边框笔触颜色

java - 如何拦截打开的短信收件箱?

c# - Android与C#之间Base64 url​​安全编解码

android - 如何显示 "Send feedback to X"对话框?

android - 在 TextInputLayout.OutlinedBox 中自定义边界框描边

android - ExtendedFloatingActionButton - 如何在按钮展开时达到与收缩时相同的高度