I can't use null for AppBarLayout.scrollFlags because I want to expand and collapse AppBarLayout by code (AppBarLayout.setExpanded
). I just don't to allow users' interactions to expand or collapse the CollapsingToolbarLayout/AppBarLayout.
Use the following code to prevent scrolling of RecyclerView or NestedScrollView from expanding or collapsing the CollapsingToolbarLayout.
// scrollView can be RecyclerView or NestedScrollViewViewCompat.setNestedScrollingEnabled(scrollView, false)
User still can expand or collapse CollapsingToolbarLayout by flicking the AppBarLayout. To prevent this from happening, use the following code.
val params = appBar.layoutParams as CoordinatorLayout.LayoutParamsif (params.behavior == null) params.behavior = AppBarLayout.Behavior()val behaviour = params.behavior as AppBarLayout.Behaviorbehaviour.setDragCallback(object : AppBarLayout.Behavior.DragCallback() { override fun canDrag(appBarLayout: AppBarLayout): Boolean { return false }})