0

How can I show a page title with more than one word without getting the second one being hidden ?

Here is the explanation:

enter image description here

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];
        }
    }
Link 88
  • 553
  • 8
  • 27

2 Answers2

0

I just had this same problem.

The default style for TabPageIndicator has android:maxLines=1

If you change it to 2 then at least the second word will show on a second line. I'm also still trying to work out how to have it all show on one line.

Denley Bihari
  • 591
  • 3
  • 8
0

From Your Layout one option should available android:Layout_weightSum flag..Please Maintain how many tabs you want to display in your screen.

Arun Kumar
  • 100
  • 1
  • 2
  • 12