我需要一个应用程序范围的标签来指示调试模式,如果激活,则在点击时创建错误报告。为了将它放在每个活动的顶部,我将其添加到窗口管理器中。非常适合该应用程序。但是某些配置是通过弹出对话框片段完成的。它们似乎处于活动状态,但对用户不可见。我已经尝试了几个布局参数标志,但没有让它工作。
以下是添加窗口的代码:
final int LayoutParamFlags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
LayoutParamFlags,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.CENTER;
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
MyLabel label = new MyLabel();
windowManager.addView(label, params);
最后,
我通过测试我脑海中出现的所有内容自行解决了这个问题。
将类型从TYPE_SYSTEM_ERROR更改为TYPE_TOAST对我来说是诀窍。它仍然覆盖所有活动,对话框也可见。我必须添加onAttachedToWindow来设置窗口令牌。
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
params.token = getWindow().getDecorView().getRootView().getWindowToken();
windowManager.addView(bugReportingLabel, params);
}