Search in sources :

Example 1 with HeaderView

use of eu.davidea.samples.flexibleadapter.views.HeaderView in project FlexibleAdapter by davideas.

the class ViewPagerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_pager);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    HeaderView headerView = (HeaderView) findViewById(R.id.toolbar_header_view);
    headerView.bindTo(getString(R.string.app_name), getString(R.string.viewpager));
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.view_pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);
    //Coordinatorlayout Status Bar Padding Disappears From Viewpager 2nd-page
    //http://stackoverflow.com/questions/31368781/coordinatorlayout-status-bar-padding-disappears-from-viewpager-2nd-page
    ViewCompat.setOnApplyWindowInsetsListener(mViewPager, new OnApplyWindowInsetsListener() {

        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            insets = ViewCompat.onApplyWindowInsets(v, insets);
            if (insets.isConsumed()) {
                return insets;
            }
            boolean consumed = false;
            for (int i = 0, count = mViewPager.getChildCount(); i < count; i++) {
                ViewCompat.dispatchApplyWindowInsets(mViewPager.getChildAt(i), insets);
                if (insets.isConsumed()) {
                    consumed = true;
                }
            }
            return consumed ? insets.consumeSystemWindowInsets() : insets;
        }
    });
}
Also used : WindowInsetsCompat(android.support.v4.view.WindowInsetsCompat) HeaderView(eu.davidea.samples.flexibleadapter.views.HeaderView) OnApplyWindowInsetsListener(android.support.v4.view.OnApplyWindowInsetsListener) TabLayout(android.support.design.widget.TabLayout) View(android.view.View) HeaderView(eu.davidea.samples.flexibleadapter.views.HeaderView) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

TabLayout (android.support.design.widget.TabLayout)1 OnApplyWindowInsetsListener (android.support.v4.view.OnApplyWindowInsetsListener)1 WindowInsetsCompat (android.support.v4.view.WindowInsetsCompat)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 HeaderView (eu.davidea.samples.flexibleadapter.views.HeaderView)1