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.
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 ?
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.
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!!!
Related
I'd like to put an indeterminate Progress Dialog material-compliant in my app. I found two ways to achieve it:
1- Using material-dialogs: https://github.com/afollestad/material-dialogs
2- Using the build-in dialogs of material-design-library: https://github.com/navasmdc/MaterialDesignLibrary#dialog
Using any of these solutions I get something pretty much like this: a dialog with a progressbar in it.
What I'd like to get is just the circular progress bar, without the surrounding light-grey view and without any text. A lot of apps proved us that the user knows that when something's spinning around he just needs to wait: there's no need to write it in letters. What I mean is pretty much something like this, but material.
I don't think this is such a strange question (or is it?) but I wasn't able to find any good answer online. Does anyone of you know how to achieve this?
Thank you
[Edit] I must say that in the gitHub issues of the material-dialogs library this seems to be discussed but the developer closes it fast by saying that it would mean not to follow the guidelines: https://github.com/afollestad/material-dialogs/issues/277
You can use this code,work fine in devices >= 19 (Kitkat)
progress = ProgressDialog.show(Splash.this, null, null, true);
progress.setContentView(R.layout.elemento_progress_splash);
progress.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
progress.show();
element progress splash.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#null"
>
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/ColorTipografiaAdeudos"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Comprobando sus datos"
android:layout_below="#+id/progressBar1"
android:layout_centerHorizontal="true"
android:id="#+id/textView6"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#color/ColorFuente"
android:layout_gravity="center_horizontal" />
</RelativeLayout>
To sum up our combined with the author efforts:
The main objective was to get a dialog appearance effect (specifically background dimming) for the progress indicator of a type "material progress wheel" with the transparent background of the dialog itself.
How we've gone about it (one of the possible ways):
This library is used as the material progress wheel.
A separate layout file is created (e.g., progress_wheel.xml) containing the progress wheel layout <com.pnikosis.materialishprogress.ProgressWheel>.... If you find yourself in a situation when the wheel's dimensions do not change as per your layout settings, wrap it with a FrameLayout with wrap_content dimensions.
Inflate this layout with a layout inflater to get a view, e.g. dialogView.
Create the dialog:
Dialog progressDialog = new Dialog(context);
progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
progressDialog.setContentView(dialogView);
progressDialog.show();
Call this function on dialogView to make the dialog background transparent:
public static void clearParentsBackgrounds(View view) {
while (view != null) {
final ViewParent parent = view.getParent();
if (parent instanceof View) {
view = (View) parent;
view.setBackgroundResource(android.graphics.Color.TRANSPARENT);
} else {
view = null;
}
}
}
How can I show a progress dialog without the message?
I only need to show the indeterminate circle. What is the easiest and fastest way of doing this without creating a custom dialog? Is there any method similar to this:
progressDialog.setShowIndeterminateCircleOnly(true)
Hope this will help some as answer is still not easily found.
ProgressDialog progDialog = ProgressDialog.show( getContext(), null, null, false, true );
progDialog.getWindow().setBackgroundDrawable( new ColorDrawable( Color.TRANSPARENT ) );
progDialog.setContentView( R.layout.progress_bar );
2nd line above will remove the box around the progress Circle icon; but it will stay left aligned by default. You will have to add the third line above to handle gravity and any other style in a XML layout file.
progress_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<ProgressBar
xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
You do not have to define the style above if you like the default smaller circle Icon
if you need a only spinning wheel without box, you can use like this.
<ProgressBar
style="?android:attr/progressBarStyle"
android:layout_gravity="center_horizontal"
android:id="#+id/progressbar_downloading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
Do only progressbar in your xml file
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
or Create ProgressDialog without setting title
ProgressDialog dialog = ProgressDialog.show(ActivityName.this, "", "", true);
dialog.setCancelable(true);
I've have a custom dialog displaying a splash screen;
mSplashDialog = new Dialog(MyActivity.this,R.layout.splash);
mSplashDialog.setContentView(R.layout.splash);
mSplashDialog.setCancelable(true);
mSplashDialog.show();
The splash layout has a ProgressBar on it;
LinearLayout
android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#drawable/picture_splash"
ProgressBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:id="#+id/progressbar_Horizontal"
android:max="100"
LinearLayout
But when I try to reference to the progress bar;
progress = (ProgressBar) findViewById(R.id.progressbar_Horizontal);
progress.setMax(100);
I've found out in the debugger that the app crashes on the second line because the object progress = null, empty zipp, nuttin :(
It seems like that the progressbar, once docked in a dialog is not accessable... :(
Somebody knows a way around this?
A ProgresDialog is not a option, because you can't customize it...
Thanks guys!
Check that you are invoking findViewById() in the correct context. For example, what you currently have is equivalent to:
progress = (ProgressBar)this.findViewById(R.id.progressbar_Horizontal);
If mSplashDialog is not part of the view hierarchy for "this", then findViewById will never find your progressBar. Perhaps you want something like:
progress = (ProgressBar)mSplashDialog.findViewById(R.id.progressbar_Horizontal);
I'm making a simple custom dialog for my android app, displaying only a seek bar. However, the complications of this simple task are driving me nuts.
My layout for the dialog is as follows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp">
<SeekBar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/dialogVolumeSlider"
android:layout_width="225dp"
android:layout_height="wrap_content"/>
</LinearLayout>
The dialog is created in code:
Dialog d = new Dialog(this);
d.setContentView(R.layout.custom_dialog);
return d;
Instead of a simple box wrapping the seekbar, I get this phantom space coming from somewhere:
What's the issue here? I've tried modifying
d.getWindow().getAttributes().height
but this creates additional problems as well.
Thanks for any help!!
EDIT: Stranger things happen when I assigned a fixed "50dp" to my LinearLayout's layout_height:
By default a Dialog will leave space for a title even if you don't set one (with d.setTitle()) .
You can either set a title to fill the space or request that the Dialog not have a title.
Here is an example of how to request the no title setting.
Dialog d = new Dialog(this);
d.requestWindowFeature(Window.FEATURE_NO_TITLE);
d.setContentView(R.layout.custom_dialog);
With no title, your SeekBar will appear as you expect.
Try putting a fixed Height on your parent linear layout. Something like:
android:layout_height="50px"
I'm using an AsyncTask to download Images for my Listview, because I dont want the download of the Images to block my UI-Thread. While the images are being loaded, I want to show an animated progress circle in the spot, where the image will be.
But I cant find an Image of the progress circle. What is the Ressource-Id? Or is there any other way? Does someone has a link to this image?
Look at the progress bar. It can work (and it does by default, AFAIR) in indeterminate mode, which means it shows a rotating circle, like the one you are asking for. I know this is not an image, but what you can do, is to place a FrameLayout instead of the image, with progress bar as the only child. Then, once the loading of the images finishes, remove the progress bar and add the image.
Define this a global variable ProgressDialog pd;
Just before launche the AsyncTask do:
pd = ProgressDialog.show(CurrentClassName.this,"This is the title","This is the detail text",true,false,null);
When its done onPostExecute just call pd.dismiss();
For more detail look at : ProgressDialog
You will have to take special considerations for it to work when you rotate the device while the dialog is up.
This is an example of a layout file for intro activity with an image and circle progress bar:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#string/intro_description"
android:scaleType="fitXY"
android:src="#drawable/intro" />
<ProgressBar
android:id="#+id/progress"
style="?android:attr/progressBarStyleInverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="150dp"
android:visibility="visible" />
</FrameLayout>
You want an indeterminate ProgressBar. Take a look at developer's website -
ProgressBar