Question

I have a CustomView which extends RelativeLayout, im adding it to screen using WindowManager.addView() method with following layout param flags

final int flags =WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;

dispatchKeyEvent() is overridden in CustomView class, but after adding it to the window when i press back button dispatchKeyEvent() is not getting called.

if i remove WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE from the flags, then dispatchKeyEvent() is getting called, but im not able to detect touch events inside the customView.

Kindly suggest flag combination via which my customView can both detect touch and key events and also touch outside the view

Please divert me to posts if this is a duplicate.

Était-ce utile?

La solution

Found the answer, just add focus flag dynamically. When your view is Visible, add the focus flag. When its invisible remove the flag to send touch events to other views.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top