无法添加窗口异常

时间:2015-06-29 08:19:24

标签: android sdk android-windowmanager

我在android 5.1中有这个错误

 Unable to add window android.view.ViewRootImpl$W@1df76e3 -- the specified window type is not valid

这是代码:

wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    params = new WindowManager.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSPARENT);
...
 wm.addView(relativeLayout, params);

1 个答案:

答案 0 :(得分:0)

在AndroidManifest中添加此权限。

android.permission.SYSTEM_ALERT_WINDOW

on API> = 23见