I'm developing for Android 4.3 and been having a problem with my code that I can't seem to figure out. I've been looking for answers for a while and all I could find was people that want my current situation while I want their bugged program.
I have 3 tabs which I've placed in the action bar by Android's tutorial for tabs in ActionBar.
What is supposed to happen: The tabs should appear on the action bar
What happens instead: The tabs appear below the action bar
My questions are:
1. How can I set those tabs to show on the ActionBar and not below
2. If succeeding 1, how can I set the size of the tabs? for example making the 3 tabs together take one third of the ActionBar (by width)
My code:
mPager = (ViewPager)findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
final ActionBar actionBar = getActionBar();
actionBar.show();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.TabListener tabListener = new ActionBar.TabListener() {
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
// show the given tab
mPager.setCurrentItem(tab.getPosition());
}
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
// hide the given tab
}
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
// probably ignore this event
}
};
mPager.setOnPageChangeListener(
new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
// When swiping between pages, select the
// corresponding tab.
actionBar.setSelectedNavigationItem(position);
}
});
// Add 3 tabs, specifying the tab's text and TabListener
actionBar.addTab(
actionBar.newTab()
.setText("A")
.setTabListener(tabListener));
actionBar.addTab(
actionBar.newTab()
.setText("B")
.setTabListener(tabListener));
actionBar.addTab(
actionBar.newTab()
.setText("C")
.setTabListener(tabListener));