Android 11 UI issues with dialog transparency

Viewed 469

did you notice any UI issues with Android OS 11(API 30). I have a full screen transparent dialog with a progressbar at center, it is working till Android 10, don't know its showing a black dark background in Android 11. Please share if you guys have any thoughts on this issue.

This is how I am setting dialog background transparent:

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

Well, setBackgroundDrawable() is deprecated now that's probably why you are getting this issue. An alternative could be setBackgroundResource(R.drawable.your_drawable) where you can replace the drawable with your color.

Struggling with same issue lead me to this solution;

    Window window = dialog.getWindow();
    window.setBackgroundDrawable(new ColorDrawable(Color.argb(58, 0, 0, 0)));
    dialog.requestWindowFeature(1);
    dialog.setContentView(R.layout.dialog_layout);//Set contentView after setting background drawable
    dialog.show();

Simple, setting the contentView after setting background drawable solved the issue. There might some other approaches like setting background as resource. This is what fit for me.

Without further details I can only make a guess on the solution. But I believe this is an issue where LayoutParams are being replaced. Instead I would suggest modifying the LayoutParams a view/window already have.

Get the layout params:

WindowManager.LayoutParams params = window.attributes;

Modify attributes as you like, e.g. params.width = WRAP_CONTENT And then set the modified layout params:

window.attributes = params

I suggest this solution to all LayoutParams, it usually give the best solution to more android versions. And less attributes has to be set.

Related