Friday, August 12, 2011

Custom Title Bars in Android

Ever get tired of the standard Android processing popup? Wouldn’t it be nice to add a processing animation to the Title bar instead of slapping on a dialogue box right in the middle of the screen that simply says “doing things”? As it turns out, that’s not such a tall order.

As it turns out, this can be done a few different ways, depending on what you want exactly. Android has a built-in “processing” animation that you can display in the Title bar. One step further, there's a loading bar baked right into Android. The Window class provides quite a few interesting settings for the title. Using the Window feature for progress turns the Window Title into a nice progress indicator that doesn’t stop the user from using the application, and also tells the user that something is happening within the app. The Window class has quite a few other features that can be set in the Title…

However, if you’re looking to show a processing animation AND some text or anything else at the same time, a bit more work has to be done. custom layout:

1: getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.newtitle);

Within newtitle.xml anything that you would like in the title bar can be set up. You can also get the views in the Title from within an Activity and change them dynamically, such as a new progress indicator. Not that the custom title flag cannot be used with any other Window flags. So if your newtitle.xml contains a Progress Bar widget, you can simply create a reference to it within your activity, and change the visibility of it whenever needed.

No comments:

Post a Comment