2017-05-08 40 views
-1

我使用窗口管理器爲鎖定充氣視圖。但是我想在它顯示對話框時多次顯示錯誤的鎖.Dialog顯示在窗口管理器的背景下充滿布局。我找不到太多。顯示對話框在視圖中充氣由windowmanager在android中

我顯示的對話框代碼:

pDialog = new SweetAlertDialog(context, SweetAlertDialog.WARNING_TYPE) 
      .setTitleText("Internet Error !") 
      .setContentText("Do you want to enable internet?") 
      .setCancelText("No,Cancel plz!") 
      .setConfirmText("Yes,Enable it") 
      .showCancelButton(true) 
      .setCancelClickListener(
        new SweetAlertDialog.OnSweetClickListener() { 
         @Override 
         public void onClick(SweetAlertDialog sDialog) { 
          sDialog.setTitleText("Cancelled!") 
            .setContentText(
              "You Can't Enable Internet") 
            .setConfirmText("OK") 
            .showCancelButton(false) 
            .setCancelClickListener(null) 
            .setConfirmClickListener(null) 
            .changeAlertType(
              SweetAlertDialog.ERROR_TYPE); 

         } 
        }) 
      .setConfirmClickListener(
        new SweetAlertDialog.OnSweetClickListener() { 

         @Override 
         public void onClick(
           SweetAlertDialog sweetAlertDialog) { 

          Intent intent = new Intent(); 
          intent.setAction(Settings.ACTION_DATA_ROAMING_SETTINGS); 
          context.startActivity(intent); 
          sweetAlertDialog.dismiss(); 

         } 
        }); 
    pDialog.getWindow().setType(
      WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); 
    pDialog.show(); 

佈局充氣,窗口管理器:

this.context = context; 
    if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { 

     Log.d("tagKrishna", "come in if"); 
    } else { 
     Log.d("tagKrishna", "come in else"); 
     numLockView = View.inflate(context, R.layout.activity_receiver, 
       null); 
     numLockView2 = View.inflate(context, 
       R.layout.activity_unclock_photo_lock_screen, null); 
     numLockView3 = View.inflate(context, 
       R.layout.unlock_pin_lock_screen, null); 

     numLockView4 = View 
       .inflate(context, R.layout.forget_passcode, null); 

     bindView(); 
     // params = new WindowManager.LayoutParams(
     // WindowManager.LayoutParams.MATCH_PARENT, 
     // WindowManager.LayoutParams.MATCH_PARENT, 
     // 2003 , 
     // 262184, PixelFormat.TRANSLUCENT); 
     params = new WindowManager.LayoutParams(
       WindowManager.LayoutParams.MATCH_PARENT, 
       WindowManager.LayoutParams.MATCH_PARENT, 
       WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, 
       WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD 
         | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH 
         | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS 
         | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, 
       PixelFormat.TRANSLUCENT); 
     windowManager = (WindowManager) context.getSystemService("window"); 
     windowManager.addView(numLockView, params); 

     init(); 
     addListener(); 

    } 
+0

哪裏碼? – Piyush

+0

添加代碼供您參考 – KrishnaJ

回答

0
AlertDialog.Builder builder = new AlertDialog.Builder(context); 
builder.setMessage("Write your message here."); 
builder.setCancelable(true); 

builder.setPositiveButton(
    "Yes", 
    new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int id) { 
      dialog.cancel(); 
     } 
    }); 

builder.setNegativeButton(
    "No", 
    new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int id) { 
      dialog.cancel(); 
     } 
    }); 

AlertDialog alert = builder.create(); 
alert.show(); 
+0

是否顯示鎖定(窗口管理器的佈局)? – KrishnaJ

+0

不,它不會在鎖上工作。 如果你想在鎖定下顯示對話框,那麼你應該使用服務來顯示對話框。 請檢查這個 http://stackoverflow.com/questions/19074466/android-how-to-show-dialog-or-activity-over-lock-screen-not-unlock-the-screen – Saim