25

There's an issue with PagerTitleStrip and PagerTabStrip with support-v4 (version 23.0.0).

The title views of a ViewPager when using PagerTitleStrip or PagerTabStrip and the version 23.0.0 (for Marshmallow/Android 6.0 support) of the support-v4 library doesn't render correctly.

Issue is tracked and scheduled for Future Release on: https://code.google.com/p/android/issues/detail?id=183127 https://code.google.com/p/android/issues/detail?id=184715

Update: This have now been resolved, in 23.1.0.

Sveinung Kval Bakken
  • 3,715
  • 1
  • 24
  • 30
  • 2
    While answering your own question is fine, it would be better if your question contained an actual question. :-) – CommonsWare Sep 03 '15 at 14:59
  • 3
    This has been fixed with the release of **support v23.1.0**. https://code.google.com/p/android/issues/detail?id=183127#c67 – Marko Oct 20 '15 at 11:52

4 Answers4

37

An interim solution while waiting for a patched release is to use a copy of the latest known good version of these classes (22.1.0) instead of the one bundled with the support library.

Drop the attached files into your project and setup your ViewPager with these classes instead.

Note: do not change their package name as they rely on package protected classes in the support library.

Example using our "new" PagerTabStrip class:

      <android.support.v4.view.ViewPager
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="wrap_content">   
          <android.support.v4.view.PagerTabStripV22
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_gravity="top"/>   
      </android.support.v4.view.ViewPager>

PagerTitleStripV22.java

PagerTabStripV22.java

W.K.S
  • 9,787
  • 15
  • 75
  • 122
Sveinung Kval Bakken
  • 3,715
  • 1
  • 24
  • 30
  • "Will be fixed maybe on v23.0.2" according to bug report: https://code.google.com/p/android/issues/detail?id=185605 – manimaul Sep 11 '15 at 14:39
  • 3
    First when you download the files from the links they will not be the correct file names i.e., the .java files will be missing the "V" for "V22", so you'll need to rename both files to "PagerTitleStripV22.java" and "PagerTabStripV22.java". Then follow these instructions posted by someone else: Create package "android.support.v4.view" in your project and drop the attached by #31 files into your project inside created package and change android.support.v4.view.PagerTabStrip to android.support.v4.view.PagerTabStripV22 in your layout file. – Brandon Sep 24 '15 at 15:48
  • Why not use TabLayout? I was trying to figure out if one is better than the other and if one doesn't actually work that's a pretty big deal breaker... – nAndroid Sep 24 '15 at 20:47
  • As far as I can tell, `TabLayout` works for more static tabs, while the `ViewPager` is backed by an adapter so it's easy to replace the dataset. I'm sure you can achieve the same with a TabLayout. – Sveinung Kval Bakken Sep 26 '15 at 16:11
  • 1
    @Brandon - You should make this an answer, it can be overlooked as a comment and it really helped me understand how to implement this solution – Belgi Oct 02 '15 at 20:44
  • 1
    @Brandon Your answer helped me implement this solution. Thumbs up! This comment should be added to the original answer as an edit, instead of creating a new answer – sga4 Oct 08 '15 at 15:36
  • How do i set the title strip to the view pager? Also, how do i control the text that needs to be displayed on the tabs in the strip? – Arjun Issar Feb 02 '16 at 10:44
6

This issue was fixed in version 23.1.0

com.android.support:support-v4:23.1.0

dercilima
  • 226
  • 2
  • 4
2

My "comment" as an answer so it's not overlooked.

First when you download the files from the links they will not be the correct file names i.e., the .java files will be missing the "V" for "V22", so you'll need to rename both files to "PagerTitleStripV22.java" and "PagerTabStripV22.java". Then follow these instructions posted by someone else: Create package "android.support.v4.view" in your project and drop the attached by #31 files into your project inside created package and change android.support.v4.view.PagerTabStrip to android.support.v4.view.PagerTabStripV22 in your layout file.

Brandon
  • 1,401
  • 1
  • 16
  • 25
1

Simple workaround to fix this issue.

//after setting the adapter
viewPager.post(new Runnable() {
    @Override
    public void run() {
        viewPager.setCurrentItem(1, false);
        viewPager.setCurrentItem(0, false);
        viewPager.postInvalidate();
    }
});

Comment the above code once the fix is released.

DreadPirateShawn
  • 8,164
  • 4
  • 49
  • 71
Metalhead1247
  • 1,978
  • 1
  • 17
  • 28