Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display progressdialog without text Android

Android 2.3.3

I have a progressdialog that shows, Loading.. as text. Here is the code for the progressdialog .

progressDialog = new ProgressDialog(mContext);                   progressDialog.setIndeterminate(true);             progressDialog.setMessage("Loading...");             progressDialog.show(); 

If I remove the line progressDialog.setMessage("Loading...");, I get a progressdialog of the left and an empty box on the right that occupies the width of the parent.

I want to display only the progressdialog , aligned at the center. Please refer to the images below..

This is what i have...

enter image description here

This is what i want...

enter image description here

Can someone help me with this?

like image 915
Vamsi Challa Avatar asked Jun 07 '13 09:06

Vamsi Challa


People also ask

What is progress dialog in Android?

ProgressDialog is a modal dialog, which prevents the user from interacting with the app. Instead of using this class, you should use a progress indicator like ProgressBar , which can be embedded in your app's UI. Alternatively, you can use a notification to inform the user of the task's progress.


2 Answers

Try this 1.create a method like this :

public static ProgressDialog createProgressDialog(Context context) {     ProgressDialog dialog = new ProgressDialog(context);     try {         dialog.show();     } catch (BadTokenException e) {      }     dialog.setCancelable(false);     dialog.getWindow()         .setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));     dialog.setContentView(R.layout.progressdialog);     // dialog.setMessage(Message);     return dialog; } 

// Xml Layout :

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_gravity="center"     android:background="@android:color/transparent" >      <ProgressBar         android:id="@+id/progressBar1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centerInParent="true" />  </RelativeLayout> 

and call this method wherever you want :

if (progressDialog == null) {     progressDialog = Utils.createProgressDialog(Login.this);     progressDialog.show(); } else {     progressDialog.show(); } 
like image 196
MuraliGanesan Avatar answered Oct 03 '22 10:10

MuraliGanesan


If you happen to get the error : "requestFeature() must be called before adding content", the solution is to call progressDialog.show() BEFORE you call progressDialog.setContentView(R.layout.progressdialog).

like image 21
yoram givon Avatar answered Oct 03 '22 08:10

yoram givon