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.

15 comments:

Gary M said...

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

Gary M 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

Josh Guilfoyle 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.

Maxence Warzecha 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

xuemei said...

Now do you worried about that in the game do not had enough shaiya gold to play the game, now you can not worried, my friend told me a website, in here you can buy a lot shaiya money and only spend a little money, do not hesitate, it was really, in here we had much cheap shaiya gold, we can sure that you will get the shaiya online gold, quick to come here to buy shaiya gold .


Now do you worried about that in the game do not had enough silkroad gold to play the game, now you can not worried, my friend told me a website, in here you can buy a lot sro gold and only spend a little money, do not hesitate, it was really, in here we had much silkroad online gold, we can sure that you will get the silk road gold, quick to come here to buy cheap silkroad gold.

xuemei said...

Now do you worried about that in the game do not had enough Sword of the New World Vis to play the game, now you can not worried, my friend told me a website, in here you can buy a lot Sword of the New World Gold and only spend a little money, do not hesitate, it was really, in here we had much cheap snw vis, we can sure that you will get the Sword of the New World money, quick to come here to buy vis.

Now do you worried about that in the game do not had enough twelve sky Gold to play the game, now you can not worried, my friend told me a website, in here you can buy a lot 12sky gold and only spend a little money, do not hesitate, it was really, in here we had much twelvesky Gold, we can sure that you will get the 12Sky Silver Coins, quick to come here to buy 12 sky gold.

Spam Diaries said...

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

steve 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

Piyush Patel 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?