Skip to content

Instantly share code, notes, and snippets.

@nitindhar7
Created January 31, 2012 03:31
Show Gist options
  • Save nitindhar7/1708574 to your computer and use it in GitHub Desktop.
Save nitindhar7/1708574 to your computer and use it in GitHub Desktop.
Fragment - creating a custom tab
// This converts the custom tab view we created and injects it into the tab widget
tab = inflater.inflate(R.layout.tab, getTabWidget(), false);
// Mainly used to set the weight on the tab so each is equally wide
tab.setLayoutParams(params);
// Add some text to the tab
label = (TextView) tab.findViewById(R.id.tabLabel);
label.setText("HOME");
// Show a thick line under the selected tab (there are many ways to show
// which tab is selected, I chose this)
divider = (TextView) tab.findViewById(R.id.tabSelectedDivider);
divider.setVisibility(View.VISIBLE);
// Intent whose generated content will be added to the tab content area
intent = new Intent(TabTutorialActivity.this, TabContentActivity.class);
// Just some data for the tab content activity to use (just for demonstrating changing content)
intent.putExtra("content", "Content for HOME");
// Finalize the tabs specification
spec = tabHost.newTabSpec("home").setIndicator(tab).setContent(intent);
// Add the tab to the tab manager
tabHost.addTab(spec);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment