Android弹出软键盘和关闭软键盘

在一些有输入框的界面中,我们需要自动弹出软键盘。比如搜索界面,输入框需要自动获取焦点并弹出软键盘。

弹出软键盘代码:

   mEditText.setFocusable(true);
   mEditText.setFocusableInTouchMode(true);
   mEditText.requestFocus();
   getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

关闭软键盘代码:

  InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
  imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
原创文章 56 获赞 44 访问量 9万+

猜你喜欢

转载自blog.csdn.net/devnn/article/details/83180816