add View by using WindowManager, but can back key press

前端 未结 3 1936
北荒
北荒 2021-01-03 07:08

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 does
3条回答
  •  我在风中等你
    2021-01-03 07:31

    Override dispatchKeyEvent of your View

        @Override
        public boolean dispatchKeyEvent(KeyEvent event)
    {
    if (event.getKeyCode() == KeyEvent.KEYCODE_BACK)
    {
        // handle back press
        // if (event.getAction() == KeyEvent.ACTION_DOWN)
        return true;
    }
    return super.dispatchKeyEvent(event);
    }
    

提交回复
热议问题