I added a custom view with WindowManager, everything is correct. Only one problem: I can’t find where to catch key events such as BACK. I noticed some of the events in the "View.dispatchKeyEvent ()" method in my user view, but not including "BACK" or "HOME". Any advice? Many thanks!
My code looks like this:
WindowManager windowManager = (WindowManager) getContext()
.getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams wmparams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT);
wmparams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
wmparams.format = PixelFormat.TRANSLUCENT;
wmparams.windowAnimations = R.style.fade;
windowManager.addView(this, wmparams);
this.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
return false;
}
});
source
share