天天看點

Android軟鍵盤開啟關閉

開啟軟鍵盤:

//調用系統輸入法
 search_bar.postDelayed({
     val inputManager: InputMethodManager =
         context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager;
     inputManager.showSoftInput(search_bar.editText, 0)
 }, 200)
           

關閉軟鍵盤:

private void hideShowKeyboard(EditText editText) {
    InputMethodManager manager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    manager.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}
           

注意,在Dialog dismiss之前調用該方法。