How to disable swiping in ViewPager2?

murgupluoglu picture murgupluoglu · Mar 4, 2019 · Viewed 15.8k times · Source

Is it possible to enable-disable swiping in new android viewpager2 component?

Answer

AskNilesh picture AskNilesh · Mar 16, 2019

Now it is possible to enable-disable swiping viewpager2 using Version 1.0.0-alpha02

Use implementation 'androidx.viewpager2:viewpager2:1.0.0-alpha02'

Version 1.0.0-alpha02

New features

  • Ability to disable user input (setUserInputEnabled, isUserInputEnabled)

API changes

  • ViewPager2 class final

Bug fixes

  • FragmentStateAdapter stability fixes

SAMPLE CODE to disable swiping in viewpager2

myViewPager2.setUserInputEnabled(false);

SAMPLE CODE to enable swiping in viewpager2

myViewPager2.setUserInputEnabled(true);