开发者

Android appwide view overlay (HUD)

I want to overlay a view over my entire app, all activities included. Think of it as a HUD (Head Up Display) over my app. The app has multiple activities, including a tab activity and the HUD doesn't interact with the user in any way, it just displays information while letting the user interact with the app as she would normally. I want this HUD for debugging purposes so I (and others) can monitor app activity and state when the phone is not attached to a debugging machine (field testing).

How do I do add such a view?

I've tried using WindowManager.addView() like so:

        WindowManager.LayoutParams lp = new W开发者_Python百科indowManager.LayoutParams(
             LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,
             WindowManager.LayoutParams.TYPE_APPLICATION,
             WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                  | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
             PixelFormat.TRANSLUCENT);
        windowManager.addView(hudView, lp);

But the HUD doesn't seem to persist in the foreground when I launch new activities it simply disappears.


I know this is an old question, but I thought I'd answer anyway since this helped me out. I was trying to get an HUD running in an openGL game and this works perfectly for that.

Since you already have the HUD displaying using the window manager, all you need to do to keep it persistant between activities is to call windowManager.addView(hudView, lp); in each activity's onResume() method. Not sure what the memory implications are though (i.e. is the view being disposed of when the window manager removes it from the screen upon switching activities), but at least it will keep the HUD up throughout the entire app.


I read that you stopped working with android, but maybe for further readers:

You missed the flag WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,. Best to implement as a view inflated by a service. Don't call it in every activity in onResume.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜