您的当前位置:首页正文

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

来源:图艺博知识网

自动弹出键盘

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对象控件
Top