4

I have an existing app that makes use of ViewPager and PagerTabStrip and this has been working for a long time with various releases of the Android SDK and the com.android.support:appcompat-v7 library. I've just bumped up the compile and target SDK versions of my app from 23 to 24 and the com.android.support:appcompat-v7 library version from 23.4.0 to 24.0.0... and I now see that the PagerTabStrip is totally missing from the ViewPager. (Not just missing titles in the PagerTabStrip... the PagerTabStrip is totally missing from the ViewPager when the views are rendered.)

This is how I'm declaring the ViewPager and PagerTabStrip views in my layout file:

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v4.view.PagerTabStrip
        android:id="@+id/pagerTabStrip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:paddingTop="8dp"
        android:paddingBottom="8dp"
        android:textColor="@android:color/white"
        android:background="@color/view_bg_blue" />

</android.support.v4.view.ViewPager>

Can anyone spot something that I'm doing wrong or could this be a bug in ViewPager and PagerTabStrip?

Adil Hussain
  • 30,049
  • 21
  • 112
  • 147
  • Btw, raised an Android support issue here: https://code.google.com/p/android/issues/detail?id=214283 – Adil Hussain Jun 26 '16 at 11:05
  • Mine only PagerTabStrip disappeared, not the fragment contents. – statosdotcom Jun 28 '16 at 23:55
  • Yes, same as what I see: the pages in the `ViewPager` are visible but not the `PagerTabStrip`. Apologies if that's not clear from my description. – Adil Hussain Jun 29 '16 at 01:51
  • Not at all, it was very clear, thank you. What I have done so far is I changed the **PagerTabStrip** to **PagerTitleStrip**. This made the title of the fragments appear again, but without the "click" funcionality, i.e.: I had to build an options menu to help sweep fragments for those who cannot figure out how to deal with my pager :( – statosdotcom Jun 29 '16 at 01:58
  • 1
    There's a workaround suggested here which you might want to try: https://code.google.com/p/android/issues/detail?id=213359 (I haven't had the opportunity to try it yet.) – Adil Hussain Jun 29 '16 at 11:58
  • 1
    Adil, many thanks for your attention. The workaround really worked for me. Very happy with this. Sorry to take your time. God bless. – statosdotcom Jun 29 '16 at 13:56

2 Answers2

15

This is the temporary workaround until the issue is resolved in the Android support library:

((ViewPager.LayoutParams) pagerTabStrip.getLayoutParams()).isDecor = true;

See here for a fuller discussion on the status of the issue: https://code.google.com/p/android/issues/detail?id=213359

Adil Hussain
  • 30,049
  • 21
  • 112
  • 147
0
We’ll start with the layout for our activity (**activity_pager_tab_strip.xml**), which in this case will just be a ViewPager containing a PagerTabStrip:
[![enter image description here][1]][1]
  [1]: https://i.stack.imgur.com/LUvF9.png

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
public class PagerTabStripActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pager_tab_strip);
        TabsPagerAdapter adapter = new TabsPagerAdapter(getSupportFragmentManager());
        ViewPager pager = (ViewPager) findViewById(R.id.pager);
        pager.setAdapter(adapter);
    }
}
Example: http://photo-wonder.blogspot.com/2016/09/using-pagertabstrip-with-viewpager.html
tienanhcntt2
  • 139
  • 1
  • 3
  • tienanhcntt2, please read the question and the accepted answer in this thread. There was a bug in the Android Support library. It is resolved now. – Adil Hussain Oct 10 '16 at 09:27