自定義AlertDialog控件的使用(AndroidStudio)


AlertDialog 第一種:可隨意自定義控件

                    第一步:自定義彈出的頁面 ,新建一個XML頁面 如下圖  不需要Activity

                        

  第二步:在主頁面設置一個按鈕彈出上圖頁面  (下面是主要代碼  調用自動以XML文件顯示在AlertDialog中)
final AlertDialog dialog = new AlertDialog.Builder(container.getContext()).create();//實例化一個AlertDialog
dialog.show();    //把AlertDialog初始化
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);//設置將輸入法顯示出來
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);  //指定輸入法顯示在該窗口  設置輸入法可見性
final Window window = dialog.getWindow(); //實例化一個窗口
window.setContentView(R.layout.activity_alert_error_document);//調用自定義的XML放到AlertDialog中展示
TextView txtDocumentNumber = (TextView) window.findViewById(R.id.txtDocumentNumber);//獲取自定義XML的控件


免責聲明!

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



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