当使用recycleview 作为聊天列表时,需要点击item关闭软键盘,
实现方式
//点击recycleView关闭输入法
recycler_view.addOnItemTouchListener(new RecyclerView.SimpleOnItemTouchListener() {
@Override
public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
if (e.getAction() == MotionEvent.ACTION_DOWN) {
SoftInputUtils.hideSoftInput(et_content, mActivity);
}
return super.onInterceptTouchEvent(rv, e);
}
});
/**
* 隐藏输入键盘
*
* @param view
* @param context
*/
public static void hideSoftInput(EditText view, Context context) {
InputMethodManager methodManager =
(InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (methodManager != null) {
methodManager.hideSoftInputFromWindow(view.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
}
网友评论