Android EditText獲取焦點和失去焦點監聽事件


實現方法也很簡單、那就是綁定OnFocusChangeListener事件、實現onFocusChange(View v, boolean hasFocus) 方法、第二個參數就是判斷得到焦點或失去焦點、從而實現我得想要的效果、代碼如下

 

EditText searchView = (EditText) findViewById(R.id.search_text); searchView.setOnFocusChangeListener(new android.view.View. OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { // 此處為得到焦點時的處理內容 } else { // 此處為失去焦點時的處理內容 } } });


免責聲明!

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



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