Android EditText獲取焦點並彈出軟鍵盤的方式
1 2 3 4 5 6 7 8 9 10 11 |
/** * EditText獲取焦點並顯示軟鍵盤 */ public void showSoftInput(EditText editText) { editText.setFocusable(true); editText.setFocusableInTouchMode(true); editText.requestFocus(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); assert imm != null; imm.showSoftInput(editText, 0); } |
如果想讓光標移動到文字末尾,加上這句代碼:
1 |
editText.setSelection(editText.getText().length()); |
感謝您的閱讀,本文由 夏之雪 原創提供。如若轉載,請註明出處:夏之雪(http://gaohanas.com/article/25929.html)