Transparent Alertdialog Has Black Background

Transparent AlertDialog has black background

The problem is that AlertDialog builder is actually not good for designing transparent dialog and will and always have this black background which is actually a Theme for it, instead use the Dialog to create a transparent theme instead.

sample:

Dialog alertDialog = new Dialog(this);
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
alertDialog.setContentView(R.layout.tabs);
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
alertDialog.show();

Using Dialog does not require any theme manipulation for transparent background so it is basically easy.

Remove Black background from Alert Dialog Box - Android

Hope this will help you a lot

I think its default theme color which is Black so you have to check the import of your AlertDialog it should be import android.support.v7.app.AlertDialog; and one more thing you should use custom color for Background like below

alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

Remove black background on custom dialog

public MyAlertDialog(
Context context,
int theme
) extends AlertDialog {

super(context, theme);
getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
}

Remove grey background for flutter alert dialog

Just launch the dialog with de navigator instead of using the showDialog() and use a PageRouteBuilder

Navigator.of(context).push(
PageRouteBuilder(
pageBuilder: (context, _, __) => AlertDialog(),
opaque: false),
);

Dialog with transparent background in Android

Add this code

 dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

Or this one instead:

dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);

Make alert dialog background transparent

If you haven't read Style attributes of custom styled AlertDialog question, you should go ahead and read. The answer suggests to use Dialog instead of Alert Dialog. Moreover reading Why does LayoutInflater ignore the layout_width and layout_height layout parameters I've specified? issue with LayoutInflater might clear a bit more. Hope it helps. Try it and let me know if it works.



Related Topics



Leave a reply



Submit