How to change the position of a progress dialog?

前端 未结 4 1177
星月不相逢
星月不相逢 2020-12-15 15:54

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

相关标签:
4条回答
  • 2020-12-15 16:25

    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.

    0 讨论(0)
  • 2020-12-15 16:40

    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);
    
    0 讨论(0)
  • 2020-12-15 16:42

    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.

    0 讨论(0)
  • 2020-12-15 16:42

    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>

    0 讨论(0)
提交回复
热议问题