对togglesoftinput函数感到困惑

时间:2012-12-18 12:36:57

标签: android

我知道该功能用于切换软输入,根据文档。但我对作为参数传递的标志如何工作感到困惑。任何一个例子都是可观的(我也想要解释,以便我得到确切的功能)。谢谢!

1 个答案:

答案 0 :(得分:-1)

显示软键盘 -

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if(imm != null){
        imm.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);
    }

隐藏SoftKeyboard -

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if(imm != null){
        imm.toggleSoftInput(0, InputMethodManager.HIDE_IMPLICIT_ONLY);
    }