簡體   English   中英

有沒有一種方法可以隱藏鍵盤而不丟失EditText的焦點

[英]Is there a way to hide the keyboard without losing the focus of the EditText

當您單擊“后退”按鈕時,鍵盤會隱藏起來,但焦點仍保留在edittext上。 如何重現此行為?

您可以使用以下代碼隱藏鍵盤:

getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
);

或者這個:

View view = this.getCurrentFocus();
if (view != null) {  
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

如果EditText失去焦點,請簡單地編寫簡單的命令

editText.requestFocus();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM