Skip to content

Instantly share code, notes, and snippets.

@nellochen
Forked from johannilsson/CustomTabListener.java
Created October 2, 2011 04:44
Show Gist options
  • Save nellochen/1257063 to your computer and use it in GitHub Desktop.
Save nellochen/1257063 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