我把這個在我的按鈕偵聽:關閉鍵盤按鈕,點擊(休息,如果沒有的EditText專注於)
InputMethodManager inputManager =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
它完全適用於鍵盤時達:它關閉鍵盤,然後繼續執行。問題是,當沒有EditText
曾經按下(他們沒有突出顯示/重點),它打破了,應用程序「停止工作」。
我想如果我能檢查EditText是否曾經被按下過,那將會很好。
我試圖做此檢查:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isActive()) // returns true if any view is currently active in the input method
{
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN);
}
編輯
我落得這樣做:
我創造了這個方法:
public static void hideSoftKeyboard (Activity activity, View view)
{
InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getApplicationWindowToken(), 0);
}
然後我在我的按鈕監聽中調用了method
NER這樣的:
hideSoftKeyboard(MainActivity.this, v); // MainActivity is the name of my class and v is the View I used in my button listener method.
你檢查了logCat,它顯示了什麼錯誤? –
@NiteshVerma我不熟悉logCat。我確實找到了一個平庸的解決方案,但是,我會發布。 –
使用豐聯 關閉/隱藏 http://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard –