Wai Yan Hein
Wai Yan Hein

Reputation: 14791

Text alignment of progress dialog in Android

I am developing an Android app. In my app , I am showing progress dialog. I can show it very easily. But the problem is as in screenshot below.

enter image description here

As you can see above the circle is aligned to left. I want to center it. I searched solutions online. But all solutions are complicated. For example I have to create custom dialog extending dialog class. But I think it is not worth to do it. Besides, I think android has the built in easy way to do it.

This is my code to show dialog:

  public void showLoginLoadingPopUp()
    {
        loadingDialog = new ProgressDialog(this);
        loadingDialog.setTitle("Loading please wait . . .");
        loadingDialog.show();

    }

As you can see, the code is so simple. I also want simple code to align circle to center of dialog without customizing dialog class.

Example loadingDialog.setTextAlign(center).

But I cannot find any function to do it. What would be the easiest way to do it ?

Upvotes: 0

Views: 1179

Answers (2)

Amit Vaghela
Amit Vaghela

Reputation: 22945

you have used setTitle() instead of that use setMessage().

public void showLoginLoadingPopUp()
    {
        loadingDialog = new ProgressDialog(this);
        loadingDialog.setMessage("Loading please wait . . .");
        loadingDialog.show();
    }

Thats it.

Upvotes: 2

Archana
Archana

Reputation: 79

Progress dialog can be upgraded with custom layout, which displays required result

ProgressDialog progressDialog = ProgressDialog.show(this, null, null, true, false);
progressDialog.setContentView(R.layout.progress_layout);

And with layout XML file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />

</LinearLayout>

Hope this helps!!!

Upvotes: 0

Related Questions