本文介绍了默认情况下隐藏键盘上点击的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要隐藏的软键盘,当我点击了编辑框的一边在屏幕上。我怎样才能做到这一点?

i want to hide the soft keyboard when i click out side of editbox in a screen. how can i do this?

推荐答案

要强制隐藏,你可以使用下面的code中的键盘......我把它放在一个名为hideSoftKeyboard()方法。正如刚才Falmarri,该softkeyboard的的隐藏自己,当你点击了它。但是,如果你叫')的onClick('的另一项该方法在,它会强行关闭键盘。

To forcibly hide the keyboard you would use the following code... I put it in a method called 'hideSoftKeyboard()'. As mentioned by Falmarri, the softkeyboard should hide itself when you click out of it. However, if you call this method in an 'onClick()' of another item, 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);
    }
}

这篇关于默认情况下隐藏键盘上点击的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 18:35