0

i m using a alert dialog box in my application,when alert dialog box appears my whole activity goes to background and a black appears.i want that when dialog box appears then my activity looks as it is as it looks before,i don't wan any background scenario?

3 Answers 3

4

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

7
  • R.style.Theme_Translucent_NoTitleBar_Fullscreen is not working with my custom dialog box.... May 15, 2012 at 10:48
  • public CustomizeDialog(Context context) { super(context); mContext = context; /** 'Window.FEATURE_NO_TITLE' - Used to hide the mTitle / requestWindowFeature(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen); // requestWindowFeature(Window.FEATURE_NO_TITLE); /* Design the dialog in main.xml file */ setContentView(R.layout.customdialog); v = getWindow().getDecorView(); v.setBackgroundResource(android.R.color.transparent); May 15, 2012 at 11:00
  • when my dialog is appear then background colour of my activity is being low,looks like little bit black,what i want is when dialog is in foreground then there is no change in background activity May 15, 2012 at 11:05
  • public class CustomizeDialog extends Dialog implements OnClickListener { @Override public void onWindowAttributesChanged(LayoutParams params) { super.onWindowAttributesChanged(params);} ContextmContext; public CustomizeDialog(Context context) { super(context); mContext =context;requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.customdialog); v = getWindow().getDecorView(); v.setBackgroundResource(android.R.color.transparent);} May 15, 2012 at 11:17
  • try: super(context, android.R.style.Theme_Translucent);
    – goodm
    May 15, 2012 at 11:20
2

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();      }   } 
0
 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();
            }
        });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.