patilmandar2007
patilmandar2007

Reputation: 322

When adding view to window with WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, it is not getting touch event

I need to display my view on top of dialer application, so I was using TYPE_PHONE for this purpose which is touchable, but still on some devices like Nexus 5 dialer application of device is hiding it.

Tried using TYPE_SYSTEM_OVERLAY makes view visible on top of dialer application, but touch is not there. Any help regarding this will be great.

Upvotes: 3

Views: 8430

Answers (1)

patilmandar2007
patilmandar2007

Reputation: 322

After lot of searching for above problem, I found solution my self. Here it is how I made view to be on top of everything inside device and also making it touchable which was not possible with TYPE_SYSTEM_OVERLAY.

WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                        WindowManager.LayoutParams.MATCH_PARENT,
                        WindowManager.LayoutParams.WRAP_CONTENT,
                        WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
                        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
                                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
                        PixelFormat.TRANSPARENT);

params.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(view, params);

Upvotes: 12

Related Questions