4

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.

enter image description here

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.

enter image description here

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

Marco Zanetti
  • 4,051
  • 6
  • 32
  • 48

2 Answers2

2

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>

enter image description here

David Hackro
  • 3,652
  • 6
  • 41
  • 61
1

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):

  1. This library is used as the material progress wheel.

  2. 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.

  3. Inflate this layout with a layout inflater to get a view, e.g. dialogView.

  4. Create the dialog:

Dialog progressDialog = new Dialog(context);
progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
progressDialog.setContentView(dialogView);
progressDialog.show();
  1. 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;
        }
    }
}
AndroidEx
  • 15,524
  • 9
  • 54
  • 50
  • Thank you but... "Material-ish Progress" this seems to me to be a progress wheel, or progress bar, not a dialog. How can I get it as a dialog with a transparent background? The same applies to the others as well... – Marco Zanetti May 07 '15 at 01:26
  • @MarKco In this case, what do you mean by a dialog? Mb I didn't get your idea correctly, but what I see on your second picture looks pretty much like a progress wheel to me. – AndroidEx May 07 '15 at 01:34
  • Probably I wasn't clear enough, I'm sorry. I'd like to get something like http://i.stack.imgur.com/h6viz.gif, as described in http://stackoverflow.com/questions/5442183/using-the-animated-circle-in-an-imageview-while-loading-stuff but that guy wanted to put the spinning wheel in the layout, I'd like to have it like an overlay dialog with all the background dimmed (as the first picture I put) but without background and words (just like the second one). Just imagine this without the words, the horizontal line and the background: http://tinyurl.com/jwc3ylm - I hope I was clearer now. – Marco Zanetti May 07 '15 at 01:50
  • @MarKco ok. What if you create a separate layout file with just this progress wheel. And then do something like this: `Dialog progressDialog = new Dialog(this); progressDialog.setContentView(R.layout.progressWheel); progressDialog.show();`. This way you should get your progress wheel in the middle of the screen, chances are it will be on transparent background, plus you'll get the dimming effect for free. Some experiments are needed, though. – AndroidEx May 07 '15 at 02:05
  • Hello, I tried with `Dialog progressDialog = new Dialog(context); progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); progressDialog.setContentView(R.layout.material_progress_dialog); progressDialog.show();` but only achieved this (after trying to make the bkg transparent and removing title bar): http://i58.tinypic.com/r8imo7.png I'd really like to remove those white space, but I don't know where it's defined :-/ I already tried styling it, didn't work either. – Marco Zanetti May 07 '15 at 07:31
  • @MarKco good. Now let's try doing it in a bit different way. All the same, but: first inflate `R.layout.material_progress_dialog` with layout inflater to get a view. Then set the view with `progressDialog.setContentView(dialogView);`. After showing the dialog, please call [this function](https://gist.github.com/Android-s14/68cd46798c9bf2351890) (pulled from my own utils) on the previously inflated view. Let's see how it goes. – AndroidEx May 07 '15 at 17:10
  • It worked! it worked!!! :-D I see your function crawls back from the view and sets the transparent android colour everywhere. Pretty clever indeed! Thank you so much! – Marco Zanetti May 07 '15 at 17:16
  • Just a small note: sizing the ProgressWheel didn't work, I had to put it in a layout and size the layout as wrap_content. Anyway, with your function transparency is granted with the layout as well :-) – Marco Zanetti May 07 '15 at 17:20
  • @MarKco glad it helped :) Hmm, interesting note, thank you. I will edit the answer in a little while today to reflect our efforts for future references. – AndroidEx May 07 '15 at 17:25
  • Hi @Android777 can i get a working sample for this plz?? – Hardik Amal Jun 19 '15 at 08:52