android - 当我使用 TYPE_APPLICATION_OVERLAY 时,对话框不可见
问题描述
我在其他应用程序之上显示一个对话框。它一直有效,直到我使用WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
当我将目标版本更改为 26 时,我不应该使用 TYPE_SYSTEM_ALERT,所以我使用了WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
之后我的对话框不可见。我还需要做什么?任何建议。
参考链接: https ://developer.android.com/about/versions/oreo/android-8.0-changes#cwt
代码:
final Dialog dialog = new Dialog(getApplicationContext());
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.permission);
dialog.setCancelable(true);
dialog.show();
解决方案
对于 oreo 及以上设备我们必须使用 TYPE_APPLICATION_OVERLAY,对于以下我们必须使用 TYPE_SYSTEM_ALERT
final Dialog dialog = new Dialog(getApplicationContext());
if(oreoAndAbove) {
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
} else {
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
}
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.permission);
dialog.setCancelable(true);
dialog.show();
推荐阅读
- sql - 如果第一个返回 NULL,则从第二个子查询中选择列
- r - 尝试从具有不同表格格式的长 PDF 中抓取
- sql - 用于计算列的 SQL 循环不同值
- python - for 循环仅从文件中读取第一行
- openshift - 通过 Openshift 4 上的 API 调用触发推出
- entity-framework-core - CreateTableOperation 结果在我自己的 CustomSqlGenerator 中的另一个操作上
- c# - 如何找到触发的行和行内容,Visual Studio 扩展
- sql - SQL 语句中缺少字符 ORA-00911
- laravel - 通过 Laravel 8 发送 ics/ical 电子邮件
- python-3.x - 使用 seaborn 的辅助 y 轴