我不是在问如何防止键盘弹出时推动屏幕。
当我点击一个EditText
时,键盘会显示出来,而屏幕保持不变。但问题是,当我点击EditText
之外的区域时,键盘隐藏起来,然后(大约半秒钟后),屏幕会跳动一下(在底部留下一个白色背景),然后再恢复正常。
我正在使用自定义键盘和自定义EditText
。
在活动中,我已经设置:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
当 EditText
获得焦点时,我会这样显示键盘:
InputMethodManager inputMethodManager = (InputMethodManager)MainApplication.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput( view, 0 );
当EditText
失去焦点时隐藏它:
InputMethodManager inputMethodManager = (InputMethodManager)MainApplication.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
编辑:
请注意,当我在键盘上按下完成时,键盘只是隐藏了(屏幕不会跳动),但EditText
并没有失去焦点。因此,如果可以在EditText
即将失去焦点时模拟一个完成按键,这对我来说就可以了。