Skip to content

Instantly share code, notes, and snippets.

@Ghedeon
Last active November 3, 2018 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ghedeon/a92ac481fa21ceeebabfaf7abf28ac78 to your computer and use it in GitHub Desktop.
Save Ghedeon/a92ac481fa21ceeebabfaf7abf28ac78 to your computer and use it in GitHub Desktop.
A ViewPager with disabled swipe.
import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.KeyEvent
import android.view.MotionEvent
import androidx.viewpager.widget.ViewPager
class NoSwipeabaleViewPager @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ViewPager(context, attrs) {
@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
return false
}
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
return false
}
override fun canScrollHorizontally(direction: Int): Boolean {
return false
}
override fun executeKeyEvent(event: KeyEvent): Boolean {
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment