1

I'm trying to add two decorations to a ViewPager. One, PageIndicator, is a custom decoration I made, and the other is a standard PagerTitleStrip.

Adding these as the ViewPager's children in the XML doesn't do anything, and at least the PageIndicator's constructor doesn't even get called. So, I'm currently using this bit of code:

mPageIndicator = new PageIndicator(this);
PagerTitleStrip strip=new PagerTitleStrip(this);

float d=getResources().getDisplayMetrics().density;

ViewPager.LayoutParams params = new ViewPager.LayoutParams();
params.isDecor = true;
params.gravity = Gravity.BOTTOM;
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
mPageIndicator.setLayoutParams(params);

ViewPager.LayoutParams params2=new ViewPager.LayoutParams();
params2.isDecor = true;
params2.gravity = Gravity.BOTTOM;
params2.height= (int) (20*d);
strip.setLayoutParams(params2);

mViewPager.addView(strip);
mViewPager.addView(mPageIndicator);

This gets executed during my activity's onStart, because I'm showing a splash screen with the same activity and calling setContentView in onStart.

This makes both decorations visible at the bottom of the view, but the title strip doesn't show any text before the view is swiped once, and swiping back shows the first page title. This behavior repeats whenever mViewPager's setAdapter is called. I have tried calling setCurrentItem twice when the adapter is set, but that doesn't seem to help.

How do I work around this?

Haem
  • 929
  • 6
  • 15
  • 31

1 Answers1

0

As CommonsWare pointed out, this is a bug with appcompat-v4 23.0.1. I managed to solve this by returning to support appcompat-v7 and appcompat-v4 version 22.2.0.

This answer to a duplicate question offers an alternative solution.

Community
  • 1
  • 1
Haem
  • 929
  • 6
  • 15
  • 31