android开发如何控制虚拟键盘的打开和隐藏

来源:互联网 发布:linux中修改文件的命令 编辑:程序博客网 时间:2024/04/27 08:16

一、如何打开虚拟键盘:

  1 InputMethodManager inputMethodManager = (InputMethodManager) 
  2     getSystemService(Context.INPUT_METHOD_SERVICE);

    // 接受软键盘输入的编辑文本或其它视图

  1     imm.showSoftInput(submitBt,InputMethodManager.SHOW_FORCED);

二、如何关闭虚拟键盘

  1     InputMethodManager inputMethodManager = (InputMethodManager)
  2     getSystemService(Context.INPUT_METHOD_SERVICE);
  3     inputMethodManager.hideSoftInputFromWindow(OpeListActivity.this.getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);

    //接受软键盘输入的编辑文本或其它视图

  1     inputMethodManager.showSoftInput(submitBt,InputMethodManager.SHOW_FORCED);

三、如何判断虚拟键盘输入法打开的状态(判断虚拟键盘是否打开)

  1     InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
  2     boolean isOpen=imm.isActive();

    说明:isOpen若返回true,则表示输入法打开

0 0