Your class has to extend TabActivity:
- public class YourClass extends TabActivity {
- ...
- ...
- }
After that, here's how to configure a Tab:1. Create a LinearLayout in your main.xml, with the id: "TabOne"
2. Paste these lines after onCreate() :
- /* TAB #1 */
- TabSpec tsTabOne = mTabHost.newTabSpec("TabOne");
- tsBrand.setIndicator("Tab One"), getResources().getDrawable(R.drawable.tab_one));
- tsTabOne.setContent(R.id.TabOne);
3. You have to create tab_one.xml in /res/drawable folder, with the following:
- <selector xmlns:android="http://schemas.android.c
om/apk/res/android"> - <!-- When selected, use this -->
- <item android:drawable="@drawable/tab_one_icon&q
uot; - android:state_selected="true" />
- <!-- When not selected, use that-->
- <item android:drawable="@drawable/tab_one_iconfa
ded" /> - </selector>
As you can see, you'll need 2 icons/tab, a normal, and a faded one.
Copy those images to "/res/drawables/" folder too, with a name like "tab_one_icon.png", or "tab_one_iconfaded.png".
4. Ok, now repeat these 3 steps above, as manytimes, as many Tabs you would like to have.5. Final Step, paste the following:
- /* Create TabHost */
- TabHost mTabHost;
- mTabHost = getTabHost();
- /* Add Tabs to TabHost */
- mTabHost.addTab(tsTabOne);
- ... /* If you have more ... */
- mTabHost.setCurrentTab(0);
2 comments :
really helpful great tutorial nice thanks !!!!!
Currently it sounds like BlogEngine is the best blogging platform out there right
now. (from what I've read) Is that what you are using on your blog?
My page - http://robinonlocation.com
Post a Comment