Show toolbar when view pager is swiped. [CoordinatorLayout]

只谈情不闲聊 提交于 2019-12-02 02:36:16

You should be able to do this using the ViewPager.OnPageChangedListener and based on the page u are on which u can get from the onPageSelected(int position) method that is part of the listener. Hope this is what u are looking for.

I was able to achieve this by referencing the AppBarLayout and calling the "setExtended" method like that:

viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            //Make sure that the fab is visible when scrolling the pages...
            MainActivity.mFloatingActionsMenu.animate()
                    .setDuration(150)
                    .translationY(0);
            //show the toolbar
            expandToolbar();

        }

        @Override
        public void onPageSelected(int position) {

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

my expandToolbar method:

public void expandToolbar(){
    //setExpanded(boolean expanded, boolean animate)
    AppBarLayout appBarLayout = (AppBarLayout)findViewById(R.id.appBarLayouy);
    appBarLayout.setExpanded(true, true);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!