[英]Show software keyboard after tap button
用戶單擊按鈕后,我需要顯示軟件鍵盤。 現在,我將隱藏鍵盤並在用戶單擊按鈕后顯示它,但是當用戶單擊“編輯文本”時,鍵盤將顯示其自身。 我有兩個按鈕,當用戶單擊第一個按鈕時,他看到軟件鍵盤,當他單擊第二個按鈕時,軟件鍵盤被隱藏,並且他看到控件片段,該片段控制edittext。 當用戶看到控件片段並點擊以獲取編輯文本時,將顯示軟鍵盤。 我需要不要顯示此軟鍵盤。 僅當用戶點擊第一個按鈕時,才顯示軟鍵盤
我如何才能停止顯示軟鍵盤,但是單擊該按鈕后它仍然可以工作?
設置editText.setFocusable(false);
初始化並單擊按鈕,使用editText.setFocusable(true);
和editText.requestFocus();
這將為您提供幫助。
editText.setInputType(InputType.TYPE_NULL);
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
});
要強制顯示軟鍵盤,可以使用
EditText yourEditText= (EditText) findViewById(R.id.yourEditText);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
而要取消對EditText的關注,可悲的是,您需要一個虛擬View來獲取焦點。
我希望這可以幫助您關閉它
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.