EditTextView:取消焦點&自動獲取焦點
一直都遇到這個問題,總是忘記,記錄一下
-
取消焦點
找到EditTextView的父控件,並設置如下即可:
android:focusable="true" android:focusableInTouchMode="true" -
自動獲取焦點
et_text.setFocusable(true); et_text.setFocusableInTouchMode(true); InputMethodManager inputManager =(InputMethodManager)et_text.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(et_text, 0); -
進入activity就獲得焦點,彈出鍵盤
et_text = (EditText) findViewById(R.id.et_text); et_text.setFocusable(true); et_text.setFocusableInTouchMode(true); et_text.requestFocus();並在清單文件中設置該Activity的屬性: android:windowSoftInputMode="stateVisible"
