Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid - How to show multi words page tile of ViewPager using IconPagerAdapter without getting second word being hidden?
    primarykey
    data
    text
    <p>How can I show a page title with more than one word without getting the second one being hidden ?</p> <p>Here is the explanation:</p> <p><img src="https://i.stack.imgur.com/wn33C.png" alt="enter image description here"></p> <p><strong>The blue tab title is a normal title with one word. The red title label contain 2 words but only 1 is shown.</strong></p> <p>Here comes the code:</p> <p>How I declare the pager in the activity:</p> <pre><code>// 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); </code></pre> <p>Pager Adapter:</p> <pre><code> /** * Extends FragmentPagerAdapter and Implemenets IconPagerAdapter (so the method getIconResId is allowed). * &lt;p&gt;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]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload