Android调用系统软键盘

时间:2023-03-09 02:44:32
Android调用系统软键盘

/**

*

* @MethodName:closeInputMethod

* @Description:关闭系统软键盘

* @throws

*/

public void closeInputMethod(){

try {

((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))

.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),

InputMethodManager.HIDE_NOT_ALWAYS);

} catch (Exception e) { }finally{ }

}

/**

*

* @MethodName:openInputMethod

* @Description:打开系统软键盘

* @throws

*/

public void openInputMethod(final EditText editText){

Timer timer = new Timer();

timer.schedule(new TimerTask() {

public void run() {

InputMethodManager inputManager = (InputMethodManager) editText

.getContext().getSystemService(

Context.INPUT_METHOD_SERVICE);

inputManager.showSoftInput(editText, 0);

}

}, 200);

}