EditTextView:取消焦點&自動獲取焦點


EditTextView:取消焦點&自動獲取焦點

一直都遇到這個問題,總是忘記,記錄一下

摘抄一下這個博客:https://www.cnblogs.com/yongdaimi/p/10606262.html

  • 取消焦點

    找到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"


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM