Android:如何在强制打开时强制关闭软键盘?

Vib*_*uti 11 android

我有一个EditText在我的Activity.一旦Activity开始我就强行打开软键盘.

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
Run Code Online (Sandbox Code Playgroud)

现在,如果软键盘打开,我按下主页按钮,它仍保持打开状态.如何在家用印刷机上强行关闭它?

Ris*_*shi 22

InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(Your Button.getWindowToken(), 0);
Run Code Online (Sandbox Code Playgroud)