AlertDialog中EditText不能擷取焦點以及不寬度不能自動鋪滿的完美解決方案,alertdialog寬度

來源:互聯網
上載者:User

AlertDialog中EditText不能擷取焦點以及不寬度不能自動鋪滿的完美解決方案,alertdialog寬度


問題分析:

因為 dialog的Attributes使用的預設的,其中一個屬性就是:flags ,就是這個屬性導致不能擷取焦點,預設的是FLAG_NOT_FOCUSABLE,故名思義不能擷取輸入焦點,所以修改這個屬性就行了。具體代碼如下:



AlertDialog dialog = new AlertDialog.Builder(context).create();        dialog.setCanceledOnTouchOutside(true);        dialog.show();        Window window = dialog.getWindow();        window.setContentView(R.layout.dialog_postmsg);        LayoutParams params = window.getAttributes();        params.width = LayoutParams.MATCH_PARENT;//如果不設定,可能部分機型出現左右有空隙,也就是產生margin的感覺        params.height = LayoutParams.WRAP_CONTENT;        params.softInputMode = LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE;//顯示dialog的時候,就顯示軟鍵盤        params.flags = LayoutParams.FLAG_DIM_BEHIND;//就是這個屬性導致不能擷取焦點,預設的是FLAG_NOT_FOCUSABLE,故名思義不能擷取輸入焦點,        params.dimAmount=0.5f;//設定對話方塊的透明程度背景(非布局的透明度)        window.setAttributes(params);

 

效果如下: 

 

 

 



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.