Created
August 9, 2012 08:35
-
-
Save AdilSoomro/3302357 to your computer and use it in GitHub Desktop.
iphone like tab host
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomTabsActivity extends TabActivity{ | |
private TabHost tabHost; | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
setTabs(); | |
} | |
private void setTabs() { | |
tabHost = getTabHost(); | |
addTab(R.string.tab_1, R.drawable.tab_home); | |
addTab(R.string.tab_2, R.drawable.tab_home); | |
addTab(R.string.tab_3, R.drawable.tab_home); | |
} | |
private void addTab(int labelId, int drawableId) { | |
Intent intent = new Intent(this, MockActivity.class); | |
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); | |
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false); | |
TextView title = (TextView) tabIndicator.findViewById(R.id.title); | |
title.setText(labelId); | |
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon); | |
icon.setImageResource(drawableId); | |
spec.setIndicator(tabIndicator); | |
spec.setContent(intent); | |
tabHost.addTab(spec); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment