簡體   English   中英

僅在特定片段中滾動時,CoordinatorLayout 隱藏工具欄

[英]CoordinatorLayout hide toolbar when scrolling only in specific fragment

我正在使用具有多個片段的單個Activity方法,在主屏幕中我有RecycleView並且我想在僅在主屏幕中滾動時隱藏工具欄,因為它是單個活動和一個頂級CoordinatorLayoutToolbar在所有屏幕中滾動時隱藏。

如何在某些屏幕中啟用“滾動時隱藏工具欄”並在單個活動中為其他屏幕禁用它?

您必須跟蹤您的活動中哪個片段(屏幕)處於活動狀態,並使用這些功能隱藏或顯示。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM