项目中,布局用scrollview做的,其中的edittext输入完毕后,无法滑动显示被软键盘遮住的页面,软键盘也只能不能在滑动的时候消失,必须点击键盘上面的小三角隐藏。
查了网上的方法,监听了scrollview的触摸事件,来解决了这个问题,滑动的时候,就让软键盘隐藏。
// 滑动隐藏软键盘
final InputMethodManager imm= (InputMethodManager) get_Activity().getSystemService(Context.INPUT_METHOD_SERVICE);
scrollview.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (get_Activity().getCurrentFocus() != null) {
if (get_Activity().getCurrentFocus().getWindowToken() != null) {
imm.hideSoftInputFromWindow(get_Activity().getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
}
}
}
return false;
}
});