How to center progress indicator in ProgressDialog easily (when no title/text passed along)
I did some testing and I feel that the best way to achieve this is doing a custom Dialog
.
Here is an example of what I did. This will answer question number 2 but will give you an idea of how to fix question number 1.
public class MyProgressDialog extends Dialog {
public static MyProgressDialog show(Context context, CharSequence title,
CharSequence message) {
return show(context, title, message, false);
}
public static MyProgressDialog show(Context context, CharSequence title,
CharSequence message, boolean indeterminate) {
return show(context, title, message, indeterminate, false, null);
}
public static MyProgressDialog show(Context context, CharSequence title,
CharSequence message, boolean indeterminate, boolean cancelable) {
return show(context, title, message, indeterminate, cancelable, null);
}
public static MyProgressDialog show(Context context, CharSequence title,
CharSequence message, boolean indeterminate,
boolean cancelable, OnCancelListener cancelListener) {
MyProgressDialog dialog = new MyProgressDialog(context);
dialog.setTitle(title);
dialog.setCancelable(cancelable);
dialog.setOnCancelListener(cancelListener);
/* The next line will add the ProgressBar to the dialog. */
dialog.addContentView(new ProgressBar(context), new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
dialog.show();
return dialog;
}
public MyProgressDialog(Context context) {
super(context, R.style.NewDialog);
}
}
All the static methods comes from this link, nothing strange, but the magic occurs in the constructor.
Check that I pass as parameter an style. That style is the following:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="NewDialog" parent="@android:Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowTitleStyle">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:background">@android:color/transparent</item>
</style>
</resources>
The result of this is a ProgressBar
rotating in the center of the screen. Without backgroundDim
and without the Dialog
box.
Android - show an indeterminate progressbar without the dialog
It's explained in full in ApiDemos inside the SDK.
The example that you want is named: ProgressBar3.java and can be found in \ApiDemos\src\com\example\android\apis\view\
Also, if you want to remove the borders of the dialog so that only the progress bar appears you can define the dialog itself as a transparent view/overlay (it's explained in the examples as well).
Progress unit in ProgressDialog
Starting from API 11, you can call the following function to achieve your purpose.
mProgressDialog.setProgressNumberFormat("%1d/%2d kB")
How to customize the Progress Dialog in Android
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<RelativeLayout
android:layout_width="135dp"
android:layout_height="56dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="146dp"
android:background="#e64b3c"
android:orientation="horizontal" >
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/progressBar1"
android:text="Please wait..." />
</RelativeLayout>
How to set the size of ProgressDialog to wrap around progress circle
It is default dialog of android, you can not change progress circle position but you can create your custom progress dialog. where you can set progress circle at any position. Here is the link and example that will help you to create your own custom progress dialog. How to create custom progressDialog
http://islandofatlas.net/2014/03/29/android-custom-progress-dialog.html
ProgressDialog size doen't change after removing text
Unfortunately only custom progress solves this.
There are a lot of samples here in stackoverflow.com
Related Topics
How to to Check If a User Has Rated Your App on the Google Play
Android - Running a Method Periodically Using Postdelayed() Call
How to Monitor Sim State Change
Android, How to Create Option Menu
How Can Write Code to Make Sharedpreferences for Array in Android
How to Show and Hide Actionbar with Appcompat V.7
Applying Colorfilter to Imageview with Shapeddrawable
Using Adb Logcat with a Real Phone (And Not the Emulator)
Why Getspeed() Always Return 0 on Android
Android Background Drawable Not Working in Button Since Android Studio 4.1
How to Run a Service Every Day at Noon, and on Every Boot
Horizontalscrollview: Auto-Scroll to End When New Views Are Added
Oauth 2.0 Authorization for Linkedin in Android
How to Record Screen and Take Screenshots, Using Android API