Android: How to Create a Modal Progress "Wheel" Overlay?
Asked Answered
H

5

8

I would like to show a modal progress "wheel" overlay on my view.

The ProgressDialog comes close, but I do not want the dialog background or border.

I tried setting the background drawable of the dialog window:

this.progressDialog = new ProgressDialog(Main.this);

this.progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
this.progressDialog.setCancelable(false);
this.progressDialog.setIndeterminate(true);

this.progressDialog.show();

but to no avail (i.e. still looks the same as without the ...setBackgroundDrawable code).

Handbreadth answered 9/3, 2010 at 12:47 Comment(1)
Should maybe repick the right answer seems the one picked is jsut a pointer to the tutorial, the one everyone is up voting has a better example.Hierarch
S
1

Have you checked out this tutorial? At the end of the page it talks about how to create a custom dialog, and that might help you put a spinner progress dialog box with your own backgrounds.

Seigneury answered 9/3, 2010 at 13:55 Comment(1)
For those wondering why this answer has few upvotes, probably this: "Caution: Android includes another dialog class called ProgressDialogthat shows a dialog with a progress bar. This widget is deprecated because it prevents users from interacting with the app while progress is being displayed." You should use the next answer and include it in your layout.Colman
S
13

Not sure if there is a better way, but you could get the spinner wheel on its own by using a ProgressBar and setting it to be interdeterminate. If you are using an AbsoluteLayout you can put it over other views. This layout should demonstrate this method with XML:

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@+id/AbsoluteLayout"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <ProgressBar android:id="@+id/ProgressBar"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:indeterminate="true" android:indeterminateOnly="true"
        android:isScrollContainer="true" android:layout_x="100dip"
        android:layout_y="10dip" android:soundEffectsEnabled="true"></ProgressBar>
    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="@string/hello"
        android:layout_gravity="center_horizontal" android:gravity="center_horizontal"
        android:layout_y="25dip" />
</AbsoluteLayout>
Stereotyped answered 9/3, 2010 at 14:48 Comment(3)
Thanks, i'm sure this would work as well, so i've voted up, but i went for the other solution as it was simpler to implement.Handbreadth
Just for everybody new to this question. AbsoluteLayout is deprecated since API Level 3. What ever that means to you guys.Tertullian
Since AbsoluteLayout is depricated, use a FrameLayout to position things on top of each other like in EZDsIt's answer.Zebe
M
11

In order to create a full screen progress on a darkened background I use a FrameLayout and set the visibility of the RelativeLayout to VISIBLE when required or GONE when the long operation is done:

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

    <ScrollView 
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:orientation="vertical"
        android:padding="3dip" >

            <!-- Your regular UI here -->

    </LinearLayout>
   </ScrollView>

   <RelativeLayout
       android:id="@+id/relativelayout_progress"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:visibility="gone"
       android:background="#aa000022" >

       <ProgressBar 
           android:layout_centerInParent="true"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:indeterminateOnly="true" />

    </RelativeLayout>
</FrameLayout>
Melisa answered 23/6, 2013 at 20:47 Comment(2)
I really like the idea of this one, pretty easy to implement. I just recommend adding an OnTouchEventListener to the RelativeLayout that returns true, so that your touch events won't be passed through to the underlying FrameLayout.Micropyle
another solution is to make FrameLayout android:clickable="true"Funk
M
3

Klarth's solution worked for me, thanks!

In my case I used the layout_gravity for center placement of the progress_indicator, rather than using explicit coordinates.

    <ProgressBar android:id="@+id/pb"
        android:layout_width="40dp" 
        android:layout_height="40dp"
        android:indeterminate="true" 
        android:indeterminateOnly="true"
        android:isScrollContainer="true" 
        android:layout_gravity="center_vertical|center_horizontal"
        android:soundEffectsEnabled="false"
        />
Melosa answered 24/3, 2011 at 23:49 Comment(0)
S
1

Have you checked out this tutorial? At the end of the page it talks about how to create a custom dialog, and that might help you put a spinner progress dialog box with your own backgrounds.

Seigneury answered 9/3, 2010 at 13:55 Comment(1)
For those wondering why this answer has few upvotes, probably this: "Caution: Android includes another dialog class called ProgressDialogthat shows a dialog with a progress bar. This widget is deprecated because it prevents users from interacting with the app while progress is being displayed." You should use the next answer and include it in your layout.Colman
H
0

you just add .setCanceledOnTouchOutside(false); to your ProgressDialog.

 ProgressDialog dialog = new ProgressDialog(getApplicationContext());
 dialog.setMessage("your message...");
 dialog.setIndeterminate(true);
 dialog.setCanceledOnTouchOutside(false);
 dialog.show();
Homeward answered 23/8, 2020 at 14:22 Comment(1)
This is deprecatedTracytrade

© 2022 - 2024 — McMap. All rights reserved.