disable the swipe gesture that opens the navigation drawer in android

后端 未结 6 1980
梦如初夏
梦如初夏 2020-12-02 06:40

I\'ve been following the navigation drawer guide by Google and I\'d like to add it to an Activity with tabs and gestures.

I\'d like to disable the gesture to open th

6条回答
  •  情话喂你
    2020-12-02 07:23

    The answer to disable swiping is the correct one. I think LOCK_MODE_LOCKED_CLOSED worked in Compat 24.x, but the functionality has been changed in newer compat libraries and LOCK_MODE_LOCKED_CLOSED now completely prevents the nav menu from showing, even via using the hamburger menu.

    The following class works for me (Kotlin):

    class MyDrawerLayout(ctx: Context) : DrawerLayout(ctx) {
      var isSwipeOpenEnabled: Boolean = true
    
      override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
          if (!isSwipeOpenEnabled && !isDrawerVisible(Gravity.START)) {
              return false
          }
          return super.onInterceptTouchEvent(ev)
      }
    
      @SuppressLint("ClickableViewAccessibility")
      override fun onTouchEvent(ev: MotionEvent): Boolean {
          if (!isSwipeOpenEnabled && !isDrawerVisible(Gravity.START)) {
              return false
          }
          return super.onTouchEvent(ev)
      }
    }
    

提交回复
热议问题