Skip to content

Instantly share code, notes, and snippets.

@johannilsson
Created September 21, 2011 14:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johannilsson/1232181 to your computer and use it in GitHub Desktop.
Save johannilsson/1232181 to your computer and use it in GitHub Desktop.
Crazy tab example
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
mFavoritesTab = buildFavoritesTab(mActionBar.newTab());
private ActionBar.Tab buildFavoritesTab(ActionBar.Tab tab) {
tab.setTabListener(mFavoritesTabListener);
TextView view = (TextView) getLayoutInflater().inflate(R.layout.tab_item, null);
view.setText(R.string.favorites);
view.setBackgroundResource(R.drawable.sub_menu_btn_left);
view.setTag(tab);
view.setOnClickListener(mOnTabClickListener);
return tab.setCustomView(view);
}
private ActionBar.TabListener mFavoritesTabListener = new CustomTabListener() {
@Override
public void onTabSelected(Tab tab) {
((TextView)tab.getCustomView()).setSelected(true);
// User clicked the tab
}
};
private abstract class CustomTabListener implements ActionBar.TabListener {
@Override
public void onTabUnselected(Tab tab) {
((TextView)tab.getCustomView()).setSelected(false);
}
@Override
public void onTabReselected(Tab tab) {
// Needed by the interface.
}
};
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:gravity="center_vertical|center_horizontal"
android:textStyle="bold"
android:textColor="@color/sub_menu"
android:focusable="true"
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment