7

I was wondering if there was any way to feature a custom title with my own drawable -- and then subsequently put a progress bar in the title layout so that it acts like the built in android progress bar.

In my code -- I want to be able to call setProgressBarIndeterminateVisibility(true) and have that display the progress bar in my custom title bar.

Is this possible?

I have set up my application theme so that it uses a custom title -- but I don't how or where to put the progress bar in that layout.

Thanks in advance.

EDIT: Right now I use my own theme that looks something like this:

<style parent="android:Theme.Light.NoTitleBar" name="BaseTheme">
    <item name="android:windowBackground">@drawable/splash_bg</item>
    <item name="android:windowTitleStyle">@style/TitleBackground</item>
</style>

With the title background style as :

<style name="TitleBackground" parent="android:WindowTitleBackground">
    <item name="android:background">@drawable/title_bar</item>
</style>

To give everyone a better idea -- something like this. alt text

hwrdprkns
  • 7,525
  • 12
  • 48
  • 69
  • If you can replace this call with another, would that work for you ? as you can never have CUSTOM_TITLE with any other title feature. – MahdeTo Aug 21 '10 at 22:04
  • I mean I could just make my own layout and use the `` to include my title on every screen -- but since I can't override the method in question I'd have to make a different method to show and hide my own progress bar -- and then put that in each activity. Well -- now that I think of it I could put it in one class and just call that class but thats still more work than I'd like to do :). – hwrdprkns Aug 21 '10 at 22:45

4 Answers4

12

Add this code in onCreate before any other code:

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS);  

setProgress(xx); // Then use this to update the progress to xx amount

To turn on/off use

setProgressBarIndeterminateVisibility(false);  //true to turn on.

I have used this in a login Activity, my problem is that I run most of the login async so I having problems updating the UI. But I do get the circular progress animation to display.

I have this working on a TabActivity being updated from an async call within an Activity Intent started by the TabActivity. I had to put the "requestWind...." lines in both the TabActivityand the called Activity. Also I have found using setProgress wasn't doing much, but the spinner animation was "spinning" the whole time so I'm happy.

Nik Reiman
  • 39,067
  • 29
  • 104
  • 160
Jim
  • 1,966
  • 3
  • 24
  • 33
4

Here is an great example of how to implement a custom title bar with a progress indicator:

http://downloadandroid.info/2010/08/creating-a-custom-titlebar/

My solution is to have an ActivityHelper class which extends Activity and includes this method as well as one to turn on or off the progress bar, then extend that class from each of my Activities.

FrederickCook
  • 3,018
  • 4
  • 24
  • 26
3

I believe the only way to do it is to use your own custom title bar. You COULD override the android code since its open source -- but that might be a bad idea. The best thing to do is to make a title bar layout and just <include /> it in all the other layouts and maybe have a helper class to show and hide the progress bar.

hwrdprkns
  • 7,525
  • 12
  • 48
  • 69
0

In newer versions the technique of requestWindowFeature will not work. A better option would be to use the v7.widget.toolbar that google has provided. The following link gives proper detail on how to use it.

Setting up the Actionbar

http://developer.android.com/training/appbar/setting-up.html

Manish M Demblani
  • 910
  • 1
  • 10
  • 21