My app is working with a FragmentPagerAdapter to add Fragments to the ViewPager. The problem is that the property android:fitsSystemWindows="true" ist not working. It doesn't add padding to the elements.
My main layout looks like following:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TabLayout
android:id="@+id/viewPagerTab"
android:layout_width="0dp"
android:layout_height="48dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:tabIndicatorColor="@android:color/transparent"/>
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/viewPagerTab"/>
</android.support.constraint.ConstraintLayout>
I set my adapter and add the fragments.
MainPagerAdapter adapter = new MainPagerAdapter(getSupportFragmentManager());
adapter.addFragment(new TestFragment(), "Test");
adapter.addFragment(new GroupFragmentManager(), "Group");
adapter.addFragment(new ProfileFragment(), "User");
viewPager.setAdapter(adapter);
viewPagerTab.setupWithViewPager(viewPager);
My pager looks like this:
private class MainPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public MainPagerAdapter(FragmentManager manager){
super(manager);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
public void addFragment(Fragment fragment, String title){
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
}
The layout of the ProfileFragment just has simple test stuff in it.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Profile"
android:fitsSystemWindows="true"/>
</LinearLayout>
But it will still not draw a padding. I also have set the right styles.
<style name="Base.Theme.SnowLink" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">#FF4081</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
I searched and tested a lot. I think android has some problems with the loaded fragments, because it works in the activity layout. I also use databinding.
Thanks in advance!