2016-03-11 76 views
-2

我有一个meme creator应用程序,我有两个文本字段和一个按钮,我希望当按钮被按下时隐藏键盘,这可能吗?如果是这样,你能帮我吗?On Button点击隐藏键盘

+0

你有什么试过这个?通常在StackOverflow上预期问题会显示一些实际代码方面的问题。 –

+0

先自己试试吧 –

+0

发表你的代码你试过的。 –

回答

4
public void dismissKeyboard(Activity activity) { 
     InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); 
     if (null != activity.getCurrentFocus()) 
      imm.hideSoftInputFromWindow(activity.getCurrentFocus() 
       .getApplicationWindowToken(), 0); 
    } 

活动必须传递给此方法,键盘将被解散。

0

你想要的应该已经发生了。当您单击按钮时,焦点将从文本字段变为按钮,因此键盘将自动隐藏。

1

可以隐藏SOF键盘与此线

InputMethodManager inputManager = (InputMethodManager) 
            getSystemService(Context.INPUT_METHOD_SERVICE); 

inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 
            InputMethodManager.HIDE_NOT_ALWAYS); 

在onclick(查看视图)事件将这个。

您需要导入android.view.inputmethod.InputMethodManager;

当您单击按钮时,键盘将隐藏。