I'm looking to display an overlay over the screen that shows a little loading ticker or possibly even some text whilst my app attempts to log into the server. My login screen is all inside of a vertical linear layout.
The effect I'm trying to achieve is something like this: http://docs.xamarin.com/recipes/ios/standard_controls/popovers/display_a_loading_message
Maybe too late, but I guess somebody might find it useful.
Activity:
Layout xml:
You have to make a background operation using thread concept like AsyncTask. Using this you can hide the actual work from the UI part. And AsyncTask will get unallocated after your operations are completed.
Android's indeterminate ProgressDialog tutorial
Splash screen while loading resources in android app
I have ProgressBar in Relative Layout and I hide or show it respectively. And yes activity can be transparent.
A spinner with a message over the application can be created using a ProgressDialog. Whilst it doesn't achieve the exact effect as in the picture, it's a good way to show that the app is working.
I like the approach in Kostya But's answer.
Building on that, here's a couple of ideas to make the same overlay easily reusable across your app:
Consider putting the overlay FrameLayout in a separate layout file, e.g.
res/layout/include_progress_overlay
:(One thing I added in the overlay FrameLayout is
android:clickable="true"
. So while the overlay is shown, it prevents clicks going through to UI elements underneath it. At least in my typical use cases this is what I want.)Then include it where needed:
And in code:
With animation code extracted into a util method:
(Here using
view.animate()
, added in API 12, instead ofAlphaAnimation
.)I had the same question, I tried the solutions but was not the best UI so, I did the followings steps.
content.background="#000000" content.alpha="0.4"