简体   繁体   中英

Coordinator Layout Behavior Not Working

I am trying to hide the toolbar when Webview is scrolled up and show when the webview is scrolled down. to achieve the behavior i found something called Coordinator Layout. But unfortunately its not working for me. How my xml looks?

<CoordinatorLayout
    -------

    <AppBarLayout
       -------
        <Toolbar
           -----
            app:layout_scrollFlags="scroll|enterAlways"
           ------
            />
    </AppBarLayout>

    <SwipeRefreshLayout
       -------------
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <WebView
            android:id="@+id/globalWebView"
            ---------------------------
            ---------------------------/>
    </SwipeRefreshLayout>

</CoordinatorLayout>

Actually when i found its not working i tried in other way that is

<CoordinatorLayout>

    <AppBarLayout>
        <Toolbar....
            app:layout_scrollFlags="scroll|enterAlways"/>
    </AppBarLayout>
        <WebView...
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</CoordinatorLayout>

But it did not worked for me. is there any solution to make it work? TIA.

Wrap your webView into NestedScrollView like below..

<CoordinatorLayout
    ....>
    <AppBarLayout>
        <Toolbar....
            app:layout_scrollFlags="scroll|enterAlways"/>
    </AppBarLayout>
    <NestedScrollView
        ....
        ...
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <WebView....
            ... />
    </NestedScrollView>
</CoordinatorLayout>

Further, You can use nestedScrollingEnabled(boolean) of NestedScrollView as needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM