Skip to content

Instantly share code, notes, and snippets.

@AdilSoomro
Created August 9, 2012 08:35
Show Gist options
  • Save AdilSoomro/3302357 to your computer and use it in GitHub Desktop.
Save AdilSoomro/3302357 to your computer and use it in GitHub Desktop.
iphone like tab host
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