天天看點

Android 全局AlertDialog對話框使用

最近在項目中,遇到了需要在項目中做一個全局的彈出框,由于是基于appcan平台的混合開發環境,是以想到了讓普通的對話框變成能覆寫應用上的對話框。

mConfirm = new AlertDialog.Builder(mContext);
                mConfirm.setTitle(inTitle);
                mConfirm.setMessage(inMessage);
.......
 mConfirm.setCancelable(false);
            AlertDialog alertDialog = mConfirm.create();
            alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR );
            alertDialog.show();
           

剛開始使用的

但是雖然修改為系統對話框,但是沒有覆寫手機下邊的虛拟按鍵(華為),導緻按桌面鍵的時候,應用退出了但是系統對話框孤零零的顯示在桌面應用上。這樣等于功能隻實作了一半,是以隻好參考WindowManager.LayoutParams.type屬性 最後經過不斷調試發現這個最符合要求

WindowManager.LayoutParams.type屬性