Sunday, March 23, 2008

Advanced Tab Activity Demo

I was inspired by the simple TabHost/TabWidget demonstration by Jeffrey Sharkey, and decided to expand upon it significantly. In my demo, I have replaced all the default drawables and layouts, created my own custom ColorStateList, and even utilized TabActivity for greater isolation.


Download: TabActivityDemo.tar.gz

The code and images for this demo are in the public domain, so please feel free to use and modify as you wish.

NOTE: TabActivity is currently marked as deprecated, but according to this post, I believe that may be in error.

13 comments:

garymm said...

thank you very much for posting this example. I think it'll end up saving me a lot of guesswork.

garymm said...

I'm running into problems. Whenever I select a tab (be it with setting a default or not but then clicking, I get a NullPointerException in TabHost$IntentContetStrategy.getContentView

Any idea what's up? I wouldn't mind showing you my code if you'd be so kind as to take a look

Unknown said...

I suppose, but I would first start by attaching a debugger (such as the one built into Eclipse) to your project and trapping the NullPointerException. Also, look at the output of adb logcat.

Unknown said...

Someone can do something similar with sdk1 ?

ATrubka said...
This comment has been removed by the author.
ATrubka said...

Everything's possible. Please see my post here:

http://tourizo.blogspot.com/2009/02/android-tabactivity-customization.html

Spam Diaries said...

It looks like they changed the API again; your example won't compile. I'll use it for inspiration, though.

Stradmin said...

Just wanted to say thanks for the demo. Saved me a lot of time!!

andcoder said...

very good post...thanks for the useful info

making of ikigai said...

Thanks for it.. Very helpful.. thanks again..

udhay said...

Many thanks for the code. ViewInflate is no more in the SDK. Its replaced by LayoutInflater.

For the code to work in latest SDK, please replace MyIndicator class as:

public static class MyTabIndicator extends LinearLayout {
public MyTabIndicator(Context context, String label) {
super(context);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View tab = inflater.inflate(R.layout.tab_indicator, this);
TextView tv = (TextView) tab.findViewById(R.id.tab_label);
tv.setText(label);
}
}

masood said...

it is not showing that bottom bar in my emulator by default it showing one in the emulator

Anonymous gurl said...

If this works it would be just amazing. After I imported the project there seems to be an error with it as it can't recognize ViewInflate type that you used in MyTabIndicator function.. Any suggestions?