Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewPagerIndicator: Multi-line text for Tab Title?

I am trying to get the tab text to display in 2 lines using the in ViewPagerIndicator using the "Sample Styled Tabs" example. Here's what I have done so far:

  • In SampleTabsStyled.java, I made the following change to GoogleMusicAdapter. Notice the new line character I added to the title string:

    @Override
    public CharSequence getPageTitle(int position) {
        StringBuilder sb = new StringBuilder(CONTENT[position % CONTENT.length].toUpperCase());
        sb.append("\n");
        sb.append(RANDOM.nextInt(1000));
        return sb.toString();
    }
    
  • In styles.xml, I made the following change:

    <style name="CustomTabPageIndicator.Text" parent="android:TextAppearance.Medium">
        <item name="android:typeface">monospace</item>
        <item name="android:singleLine">false</item>
    </style>
    

However, I only see the first line of text in the VPI tabs. I don't see the second line of numbers. What might I be doing wrong?

like image 455
curioustechizen Avatar asked Jan 11 '13 12:01

curioustechizen


1 Answers

I found the answer with help on G+. Here's what I had to do:

  • Don't bother with modifying the style for CustomTabPageIndicator.Text. I reverted it to the original.
  • Add the following line to the style for CustomTabPageIndicator:

    <item name="android:maxLines">2</item> 
    

That did it for me.

like image 133
curioustechizen Avatar answered Oct 07 '22 17:10

curioustechizen