简体   繁体   中英

Alert dialog box in android

我在应用程序中使用警报对话框,当警报对话框出现时,我的整个活动都变成了背景并且出现了黑色。我希望当对话框出现时,我的活动看起来像以前一样,我不想任何背景情况?

You need to use transparent flag for your dialog. But probably you gonna need to create your custom dialog for it:

Dialog mDialog = new Dialog(mContext, android.R.style.Theme_Translucent);

Custom dialog: android dialog transparent

AlertBox: Set Transparent Window in AlertDialog box

Try this:

 public class CustomDialog extends Dialog implements OnClickListener {      
  Button button_home,button_cancel,button_resume;     
    public GamePauseMenu(Context context) {          
      super(context,R.style.Theme_Transparent);      
      }     


    public void show(int bg) {              
             super.show();         
           setContentView(R.layout.custdialog);       
            button_resume = (Button)findViewById(R.id.imageButton1);                  button_resume.setOnClickListener(this);    
     }     public void onClick(View v) {         cancel();      }   } 
 b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog.Builder alertDialog2 = new AlertDialog.Builder(
                        MainActivity.this);

// Setting Dialog Title
                alertDialog2.setTitle("Confirm Delete...");

// Setting Dialog Message
                alertDialog2.setMessage("Are you sure you want delete this file?");

// Setting Icon to Dialog
               // alertDialog2.setIcon(R.drawable.delete);

// Setting Positive "Yes" Btn
                alertDialog2.setPositiveButton("YES",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                // Write your code here to execute after dialog
                                Toast.makeText(getApplicationContext(),
                                        "You clicked on YES", Toast.LENGTH_SHORT)
                                        .show();
                            }
                        });

// Setting Negative "NO" Btn
                alertDialog2.setNegativeButton("NO",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                // Write your code here to execute after dialog
                                Toast.makeText(getApplicationContext(),
                                        "You clicked on NO", Toast.LENGTH_SHORT)
                                        .show();
                                dialog.cancel();
                            }
                        });

// Showing Alert Dialog
                alertDialog2.show();
            }
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM