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?
Asked
Active
Viewed 2,325 times
3 Answers
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
-
R.style.Theme_Translucent_NoTitleBar_Fullscreen is not working with my custom dialog box.... – user1227605 May 15 '12 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); – user1227605 May 15 '12 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 – user1227605 May 15 '12 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);} – user1227605 May 15 '12 at 11:17
-
try: super(context, android.R.style.Theme_Translucent); – goodm May 15 '12 at 11:20
-
i just test it and it works for me. Maybe there is something wrong with your xml layout? – goodm May 15 '12 at 11:37
-
there is xml in Custom Dialog example link which I included to my answer – goodm May 15 '12 at 11:43
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();
}
});

PeterPan
- 1
- 1