How can I show a page title with more than one word without getting the second one being hidden ?
Here is the explanation:
The blue tab title is a normal title with one word. The red title label contain 2 words but only 1 is shown.
Here comes the code:
How I declare the pager in the activity:
// Icons in pager tabs
int[] icons = new int[] {
R.drawable.ic_tab_contestazione,
R.drawable.ic_tab_note,
R.drawable.ic_tab_camera };
// Prepares the adapter to attach to the pager
mAdapter = new NuovaViolazioneAdapter(getSupportFragmentManager(), icons);
// Inflates pager
mViewPager = (SwipeableViewPager) findViewById(R.id.viol_classica_pager);
mViewPager.setAdapter(mAdapter);
mViewPager.setSwipeable(false);
// Inflates tab indicator (the upper clickable/scrollable bar)
mIndicator = (TabPageIndicator) findViewById(R.id.indicator);
mIndicator.setViewPager(mViewPager);
// Sets the current page (used when rotated)
int page = getIntent().getIntExtra(WHICH_PAGE, 0);
mIndicator.setCurrentItem(page);
Pager Adapter:
/**
* Extends FragmentPagerAdapter and Implemenets IconPagerAdapter (so the method getIconResId is allowed).
* <p>Sets which fragment has to be inflated for each position. Sets the tab title for each fragement.
*/
class NuovaViolazioneAdapter extends FragmentStatePagerAdapter implements IconPagerAdapter {
private int[] icons;
public NuovaViolazioneAdapter(FragmentManager fm, int[] icons) {
super(fm);
this.icons = icons;
}
@Override
public Fragment getItem(int position) {
switch (position) {
case POSITION_M_CONTESTAZIONE:
return MContestazioneFragment_.getInstance();
case POSITION_NOTE:
return NoteFragment_.getInstance();
case POSITION_FOTO:
return FotoFragment_.getInstance();
}
return null;
}
@Override
public CharSequence getPageTitle(int position) {
return NuovaViolazioneActivity.CONTENT[position
% NuovaViolazioneActivity.CONTENT.length]
.toUpperCase(Locale.ITALIAN);
}
@Override
public int getIconResId(int index) {
return icons[index];
}
}