[英]Hide Toolbar with CoordinatorLayout, but RecyclerView on a fragment
[英]CoordinatorLayout hide toolbar when scrolling only in specific fragment
我正在使用具有多个片段的单个Activity
方法,在主屏幕中我有RecycleView
并且我想在仅在主屏幕中滚动时隐藏工具栏,因为它是单个活动和一个顶级CoordinatorLayout
, Toolbar
在所有屏幕中滚动时隐藏。
如何在某些屏幕中启用“滚动时隐藏工具栏”并在单个活动中为其他屏幕禁用它?
您必须跟踪您的活动中哪个片段(屏幕)处于活动状态,并使用这些功能隐藏或显示。
fun enableLayoutBehaviour() {
val layoutParams: CoordinatorLayout.LayoutParams = coordinatorLayout.layoutParams
layoutParams.behavior = AppBarLayout.ScrollingViewBehavior()
}
fun disableLayoutBehaviour() {
val layoutParams: CoordinatorLayout.LayoutParams = coordinatorLayout.layoutParams
layoutParams.behavior = null
}
@Yonatan 在我的情况下的回答还不够,在片段之间导航时,底部看不到一些视图,可能是一些高度配置错误。
为Toolbar
启用和禁用滚动标志就可以了。
public void disableToolbarScrollBehavior() {
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
params.setScrollFlags(0);
}
public void enableToolbarScrollBehavior() {
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.