android - 如何在 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() 活动
解决方案
如果您需要在 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 )
希望这有帮助!
推荐阅读
- ios - React Native OneSignal 集成错误 openURL:options:completionHandler:' 不可用
- angular - 我们如何处理 Angular 中的表单组密码匹配?
- git - 发布分支的 Git 合并策略
- reactjs - 推送被拒绝,无法在 Heroku 上的 Reactjs 中编译 Node.js 应用程序
- sql - 如何在 SQL 中将这 3 个表连接在一起?
- javascript - Javascript addEventListener 传递函数指针
- python - 在 Python 中确保精确的浮点结果
- python - 如何在后台运行 Python Docker 容器并在我的命令中使用它们?
- codeigniter - 找不到控制器方法时的 Codeigniter 4 测试
- javascript - vue 2.5.17 Medium Bump vue-server-renderer 对 serialize-javascript 到 2.1.2 的依赖