2013-03-20 78 views
1

我使用下面的代码作为util文件方法来隐藏我的小键盘,只要我点击一个按钮。在android中隐藏小键盘

public static void hideKeyPad(){ 
     Activity activity = MainActivity.getActivity(); 
     InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); 
     imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); 
    } 

但键盘一直在来。请纠正我。

+1

请添加您的布局xml – 2013-03-20 07:56:36

+0

是否要禁用android键盘? – 2013-03-20 07:59:12

回答

2

尝试使用此代码,它的工作对我来说

InputMethodManager inputManager = (InputMethodManager) 
       getSystemService(Context.INPUT_METHOD_SERVICE); 
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 
        InputMethodManager.HIDE_IMPLICIT_ONLY); 
+0

仍然不适合我。 – vignesh 2013-03-20 12:24:14

0

使用hideSoftInputFromWindow方法和你EditText的第一个参数传递的窗口令牌。

InputMethodManager inputManager = (InputMethodManager) 
       getSystemService(Context.INPUT_METHOD_SERVICE); 
inputManager.hideSoftInputFromWindow(yourEdit.getWindowToken(), 0);