美文网首页
Android开发中如何控制输入法键盘弹出与收起

Android开发中如何控制输入法键盘弹出与收起

作者: 仍是少年呀 | 来源:发表于2016-11-02 11:55 被阅读246次

    自动弹出键盘

    InputMethodManager inputMethodManager = (InputMethodManager)this.getSystemService(Activity.INPUT_METHOD_SERVICE);
    inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
    //其中,showSoftInput方法第一个参数为指定的EditText的控件对象
    

    自动收起键盘

    InputMethodManager inputMethodManager = (InputMethodManager) this.getSystemService(Activity.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(editText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    //同上,editText也为你要收起键盘的那个EditText对象控件
    

    相关文章

      网友评论

          本文标题:Android开发中如何控制输入法键盘弹出与收起

          本文链接:https://www.haomeiwen.com/subject/dzyvuttx.html