Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add View by using WindowManager, but can back key press

I've add a View, by using WindowManager.

It shows properly what I wanted to do,

but I have a problem. this is the problem.

  • back key press doesn't affect under android component(like activity)

what I want is my added view can focusable, ( can click the view's inner button ) only when click the view, and outside of the view can process their work. ( for example, if there is a button, can be clicked, and when back key press, top activity was gone )

but if I add a flag - WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, then I can't receive onClick method on my added view's button. but back button work correctly.

otherwise, if i remove the flag -I can receive onClick callback, but now back button doesn't work.

I have a dilema. :(

Thank you.

like image 293
nolleh Avatar asked Jan 15 '23 07:01

nolleh


1 Answers

Have your View override

public boolean dispatchKeyEvent(KeyEvent event) 

to do something when back is pressed.

like image 183
ebtokyo Avatar answered Jan 19 '23 00:01

ebtokyo