Android PopupWindow中EditText擷取焦點自動彈出軟鍵盤

來源:互聯網
上載者:User

標籤:

公司的項目中要求在點擊搜尋的時候彈出一個搜尋方塊,搜尋方塊中有一個EditText,用於資料搜尋索引鍵,要求在彈出PopupWindow的時候自動彈出軟鍵盤,原以為只要寫上著兩行代碼可以搞的問題:

1 InputMethodManager inputMethodManager=(InputMethodManager) et_search_key.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);2 inputMethodManager.showSoftInput(et_search_key, 0);

在運行調試的時候,問題來了,沒有按照設想的那樣,顯示軟鍵盤。接下來就是找資料,試了好多方法,就是不行,最後使用Handler非同步成功了。下面貼出代碼:

 1 private void showSoft(){ 2         Handler handle=new Handler(); 3         handle.postDelayed(new Runnable() { 4              5             @Override 6             public void run() { 7                 InputMethodManager inputMethodManager=(InputMethodManager) et_search_key.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); 8                 inputMethodManager.showSoftInput(et_search_key, 0); 9             }10         }, 0);11     }

 

Android PopupWindow中EditText擷取焦點自動彈出軟鍵盤

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.