Is the user theme dialog centered programmatically?

I have a dialog with a custom theme:

final Dialog d = new Dialog(this,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen); 

This makes my background dialogue transparent.

Now the problem is that if I solve the normal theme (style.dialog), it will be centered on my screen, but now it has no layout and is in the upper left corner of the screen. Is there a way to programmatically center the dialogue?

+4
source share
2 answers

In fact, I did not find a software solution to my problem, instead, in my customdialog.xml, I placed the main layout in a RelativeLayout with fill_parent for height / width, and then placed the attribute atribute centerInParent = "true".

+3
source

build your dialog by expanding the dialog, override the style and content (using setContentView)

-3
source

Source: https://habr.com/ru/post/1397580/


All Articles