How to change the position of a progress dialog?
Asked Answered
B

4

34

I'm developing an android app and need to know how to change the positioning of a progress dialog. I need it to be positioned at the bottom of the screen instead of at the center like it is by default.

Brinkema answered 2/8, 2010 at 22:22 Comment(0)
F
83

You can call ProgressDialog#getWindow#setGravity(...) to change the gravity.

So:

ProgressDialog dialog = ProgressDialog.show(AContext, "Test", "On the bottom");
                dialog.getWindow().setGravity(Gravity.BOTTOM);
Fasces answered 3/8, 2010 at 0:48 Comment(0)
B
19

In addition to the other answers you can use LayoutParams.x or LayoutParams.y to provide an offset from the given edge. For Example:

progressDialog = ProgressDialog.show(this, "Title","Text");

progressDialog.getWindow().setGravity(Gravity.TOP);
LayoutParams params = progressDialog.getWindow().getAttributes();
params.y = 100;
progressDialog.getWindow().setAttributes(params);

And it is good for you to know about LayoutParams.y:

Y position for this window. With the default gravity it is ignored. When using TOP or BOTTOM it provides an offset from the given edge.

and about LayoutParams.x:

X position for this window. With the default gravity it is ignored. When using LEFT or START or RIGHT or END it provides an offset from the given edge.

Britney answered 24/12, 2012 at 8:1 Comment(1)
Thanks for the additional information. I don't need it today, but I will in the future.Jorry
C
3

If you're using any custom theme for the ProgressDialog, Then you could add the below xml tag to the style in your style.xml file of the custom theme

<item name="android:layout_gravity">bottom</item>

Cristoforo answered 30/11, 2015 at 9:4 Comment(0)
P
1

Adding android:gravity="bottom" to the outermost XML element in the layout might do it. Not sure if this moves the dialog or the contents of it.

Pita answered 2/8, 2010 at 23:15 Comment(1)
This won't bring the dialog to the bottom of the screen. It can move the content to the bottom of the parent view.Cristoforo

© 2022 - 2024 — McMap. All rights reserved.