How to capture the “virtual keyboard show/hide” event in Android?

前端 未结 16 1374
暗喜
暗喜 2020-11-22 07:23

I would like to alter the layout based on whether the virtual keyboard is shown or not. I\'ve searched the API and various blogs but can\'t seem to find anything useful.

16条回答
  •  自闭症患者
    2020-11-22 08:11

    I solve this by overriding onKeyPreIme(int keyCode, KeyEvent event) in my custom EditText.

    @Override
    public boolean onKeyPreIme(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
            //keyboard will be hidden
        }
    }
    

提交回复
热议问题