2017-08-25 44 views
1

Android studio版本:2.3.3 下面的代码不能正常工作,它应该隐藏键盘,但它不是。请帮助。Android Studio - 输入法管理器

InputMethodManager imm = (InputMethodManager) 
    getSystemService(Context.INPUT_METHOD_SERVICE); 
    public void setImm(InputMethodManager imm) { 
    this.imm = imm; 
    } 
    public InputMethodManager getImm() { 
    imm.hideSoftInputFromWindow(urledit.getWindowToken(),0); 
    return imm; 
    } 
+0

嗨,欢迎堆栈溢出。有关如何提出问题并更新您的问题的更多详细信息,请参见[问问]链接 。 –

回答

0
/** 
* Hides the soft keyboard 
*/ 
public void hideSoftKeyboard() { 
    if(getCurrentFocus()!=null) { 
    InputMethodManager inputMethodManager = (InputMethodManager) 
getSystemService(INPUT_METHOD_SERVICE); 
    inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); 
    } 
} 

/** 
* Shows the soft keyboard 
*/ 
public void showSoftKeyboard(View view) { 
    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); 
    view.requestFocus(); 
    inputMethodManager.showSoftInput(view, 0); 
} 

试试这个隐藏和显示键盘

+0

仍然无法正常工作。感谢您的帮助 –

+0

您能否展示您的实施 – Android

0

希望对大家有用

public static void hideKeyboard(Activity activity) { 
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); 
View view = activity.getCurrentFocus(); 
if (view == null) { 
    view = new View(activity); 
} 
imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 
}