首页 > 解决方案 > 如何在 Android 主屏幕上显示自定义对话框?科特林

问题描述

如何在 Android 主屏幕上显示自定义对话框?首先创建 BroadcastReceiver()

第二次将CustomDialog创建为Activity

添加到清单

<activity android:name=".view.activity.CustomDialog"
        android:launchMode="singleInstance"
        android:screenOrientation="fullSensor"
        android:theme="@style/AlertDialogTheme"
        />

将 Style AlertDialogTheme 添加到 style.xml

<style name="AlertDialogTheme" parent="Theme.MaterialComponents.Light.Dialog.Alert.Bridge">

</style>

第三次按意图移动到 CustomDilog() 活动

标签: androidkotlindialog

解决方案


如果您需要在 android 主屏幕上显示对话框。您需要为该对话框设置窗口类型:示例:

val type = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
        } else {
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
        }
dialog?.window?.setType(type )

希望这有帮助!


推荐阅读