When using tabs on the action bar, sometimes they appear as “folded” when the contents of the tab are too large to display. The problem arises when I use a custom view for the contents of the tab, it causes the selected tab not to appear in the drop-down list, and as soon as the tab is selected, the popup menu disappears and small empty tabs appear.
Here is a screenshot of the drop-down list before selecting an item: (note that the contents of the tab are not displayed, even if the tab is selected)

In addition, after selecting an item, the tabs are no longer stacked, and the contents of the tabs are empty:

Here is my code (note that I am using a custom tab view to demonstrate the problem)
public class ExampleActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final TextView selectedTabText = new TextView(this);
setContentView(selectedTabText);
ActionBar.TabListener listener = new ActionBar.TabListener() {
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
TextView customView = (TextView) tab.getCustomView();
selectedTabText.setText(customView.getText());
}
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
};
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
addTab(actionBar, listener, "Tab one with a very long name");
addTab(actionBar, listener, "Tab two with a very long name");
addTab(actionBar, listener, "Tab three with a very long name");
addTab(actionBar, listener, "Tab four with a very long name");
}
private void addTab(ActionBar actionBar, ActionBar.TabListener listener, String text) {
ActionBar.Tab tab = actionBar.newTab();
TextView textView = new TextView(this);
textView.setText(text);
tab.setCustomView(textView);
tab.setTabListener(listener);
actionBar.addTab(tab);
}
}
source
share