Android : Displaying tabs on single screen of ActionBar tabs Android

on Friday, September 19, 2014


Iam using Scrollable tabs in ActionBar. Right now I have 3 tabs. But like the image below the third tab goes out of the screen I want them to be in a single screen. How do I do it?


enter image description here


Here is my code:-



for (int i= 0; i< tabs.length && i< icons.length; i++)
{

actionBar.addTab(actionBar.newTab().setText(tabs[i]).setIcon(icons[i])
.setTabListener(this));
}


//Change ActionBar color
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#009788")));
//Change TabColor
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#00796A")));

/**
* on swiping the viewpager make respective tab selected
* */
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

@Override
public void onPageSelected(int position)
{
// on changing the page
// make respected tab selected
actionBar.setSelectedNavigationItem(position);
}

@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}

@Override
public void onPageScrollStateChanged(int arg0) {
}
});

}

0 comments:

Post a Comment