How to change FloatingActionButton between Tabs?

后端 未结 7 864
囚心锁ツ
囚心锁ツ 2021-01-30 02:28

I\'m trying to implement FloatingActionButton from Google Design Support Library into two of three tabs, and according to t

7条回答
  •  情书的邮戳
    2021-01-30 03:15

    you can add a listener to viewpager and show and hide fab according to its state when you start scrolling the viewpager this is the order of states SCROLL_STATE_DRAGGING SCROLL_STATE_SETTLING SCROLL_STATE_IDLE

    for example:

    viewPager.addOnPageChangeListener(this);
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }
    
        @Override
        public void onPageSelected(int position) {
    
        }
    
        @Override
        public void onPageScrollStateChanged(int state) {
            if(state==ViewPager.SCROLL_STATE_IDLE)
                fab.show();
            else if(state==ViewPager.SCROLL_STATE_DRAGGING)
                fab.hide();
    
        }
    

提交回复
热议问题