隐藏键盘后屏幕跳转
Screen jumps after hiding keyboard
我不是问如何防止键盘弹出时把屏幕推上去
当我点击 EditText
时,键盘出现,屏幕保持不变。但问题是当我在 EditText
之外单击时,键盘隐藏 然后 (大约半秒后)屏幕跳转一点点(在底部留下白色背景)然后安定下来。
我正在使用自定义键盘和自定义 EditText。
在 activity 我设置了:
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);
编辑:
不是当我在键盘上按 DONE 时,键盘只是隐藏(没有屏幕跳转)但 EditText 不会失去焦点。因此,如果可以在 EditText
即将失去焦点时模拟 DONE 按下,这对我来说没问题。
我是这样解决的:
我在主布局上设置了一个 OnTouchListener
(它是一个 LinearLayout
)并在那里隐藏了键盘:
mainLinearLayout.setOnTouchListener( new OnTouchListener() {
@Override
public boolean onTouch( View v, MotionEvent event ) {
InputMethodManager inputMethodManager = (InputMethodManager)MainApplication.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
return false; //*SEE NOTE BELOW
}
} );
*注意:
原来如果我returntrue
(事件被消耗),键盘隐藏了,但是EditText
没有失去焦点。而如果我 return false
(事件还没有被消费),键盘隐藏,并且 EditText
失去焦点(无论哪种方式,都没有屏幕跳转)
我不是问如何防止键盘弹出时把屏幕推上去
当我点击 EditText
时,键盘出现,屏幕保持不变。但问题是当我在 EditText
之外单击时,键盘隐藏 然后 (大约半秒后)屏幕跳转一点点(在底部留下白色背景)然后安定下来。
我正在使用自定义键盘和自定义 EditText。
在 activity 我设置了:
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);
编辑:
不是当我在键盘上按 DONE 时,键盘只是隐藏(没有屏幕跳转)但 EditText 不会失去焦点。因此,如果可以在 EditText
即将失去焦点时模拟 DONE 按下,这对我来说没问题。
我是这样解决的:
我在主布局上设置了一个 OnTouchListener
(它是一个 LinearLayout
)并在那里隐藏了键盘:
mainLinearLayout.setOnTouchListener( new OnTouchListener() {
@Override
public boolean onTouch( View v, MotionEvent event ) {
InputMethodManager inputMethodManager = (InputMethodManager)MainApplication.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
return false; //*SEE NOTE BELOW
}
} );
*注意:
原来如果我returntrue
(事件被消耗),键盘隐藏了,但是EditText
没有失去焦点。而如果我 return false
(事件还没有被消费),键盘隐藏,并且 EditText
失去焦点(无论哪种方式,都没有屏幕跳转)