Android全屏AlertDialog

发布于 2025-02-08 08:23:30 字数 1490 浏览 2 评论 0 原文

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

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

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>

I'm trying to make a full screen dialog in my Android application, but I'm not able to expand it to the status bar. You can see the gray status bar in the image below.

EDIT 1:
It seems to be a problem related to the operating system installed and not to the Android components, because I'm experiencing this problem only on certain devices.

enter image description here

AlertDialog creation:

    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:

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何时共饮酒 2025-02-15 08:23:30

是的,它具有相机缺口

可以通过覆盖相机缺口区域(切割显示区域)使您的对话框全屏,您需要明确调整显示切口到 shortedges 始终使用 Android:WindowLayOutIndisPlayCutOutMode 对话框主题中的属性:

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

在这里进行进一步研究;

yes, it has camera notch

To make your dialog a full screen by covering the camera notch area (cutout display area), you need to explicitly adjust the display cutout to shortEdges or always using android:windowLayoutInDisplayCutoutMode attribute in the dialog theme:

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

Please check documentation here for further research;.

南渊 2025-02-15 08:23:30

尝试以下操作:


 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)
           var dialog= builder.show()
            dialog.window.setLayout(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT)

try this:


 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)
           var dialog= builder.show()
            dialog.window.setLayout(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文