如何在单选按钮上隐藏软键盘

时间:2014-05-26 04:58:57

标签: android android-softkeyboard

我正在开发一个动态创建布局的应用程序。 我有一个问题,我想在有RadioButton时隐藏键盘。我有5个连续编辑文本框(动态生成)。之后,RadioButton部分开始。我想在有收音机按钮时隐藏键盘,并在出现编辑文本时再次显示。

我试过了:

InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

但没有运气。

1 个答案:

答案 0 :(得分:3)

 if you call this method in an 'onClick()'  it will forcibly close the keyboard.

private void hideSoftKeyboard(){
    if(getCurrentFocus()!=null && getCurrentFocus() instanceof EditText){
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(yourEditTextHere.getWindowToken(), 0);
    }
}
相关问题