Search code examples
androidtabsactionbarsherlock

ActionBarSherlock with Tabs


I am trying to implement ActionBarSherlock with three tabs in the way that the tabs are placed in the same line as HomeButton. See the picture below: enter image description here

I created the ActionBarSherlock and added the three tabs but they did not appear on the screen. What did I miss?

Here is my code:

    //ActionBarSherlock settings
    ActionBar actionBar=getSupportActionBar();
    Resources res=getResources();
    actionBar.setDisplayUseLogoEnabled(true);
    actionBar.setLogo(res.getDrawable(R.drawable.logo));
    actionBar.setSplitBackgroundDrawable(res.getDrawable(R.drawable.separator));
    actionBar.setBackgroundDrawable(res.getDrawable(R.drawable.navbar));
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);

    //Tabs
    actionBar.addTab(actionBar.newTab().setText("apps").setIcon(R.drawable.ico_apps_normal).setTabListener(this).setTag("apps tab"),true);
    actionBar.addTab(actionBar.newTab().setIcon(R.drawable.ico_add_normal).setTabListener(this).setTag("add tab"));
    actionBar.addTab(actionBar.newTab().setIcon(R.drawable.ico_news_normal).setTabListener(this).setTag("news tab"));

Solution

  • Try adding

    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    

    before you start adding your tabs. It seems like you haven't set your navigation mode.

    I've also answered a similar question regarding Actionbars and navigaton tabs here