简体   繁体   English

滚动时隐藏工具栏

[英]hide Toolbar while scrolling

I have TabLayout below Toolbar and below the TabLayout I have SearchLayout (CustomView) I need to hide Toolbar while scrolling.我有TabLayout下方Toolbar和下方的TabLayout我有SearchLayout(CustomView)我需要隐藏Toolbar ,而滚动。 I tried many ways but it's not happening Is there any solution for the same?我尝试了很多方法,但没有发生 是否有相同的解决方案?

在此处输入图片说明

Here is my xml code这是我的 xml 代码

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <include
        android:id="@+id/toolbar_search_screen"
        layout="@layout/toolbar"
        app:layout_scrollFlags="scroll|enterAlways" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        style="@style/AppTabLayout"
        android:layout_width="match_parent"
        android:layout_height="@dimen/_45sdp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/tool_bar"
        app:tabGravity="fill"
        app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>

<RelativeLayout
    android:id="@+id/search_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/_90sdp">

    <include layout="@layout/search_layout" />
</RelativeLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="@dimen/_45sdp"
    android:overScrollMode="never"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

Just add appropriate scroll flags to Toolbar :只需向Toolbar添加适当的滚动标志:

app:layout_scrollFlags="scroll|enterAlways"

And appropriate behavior to the scrolling view (in your case to SwipeRefreshLayout and ViewPager ):以及滚动视图的适当行为(在您的情况下为SwipeRefreshLayoutViewPager ):

app:layout_behavior="@string/appbar_scrolling_view_behavior"

Inside viewPager views, it's children must be scrollable, otherwise it won't work.在 viewPager 视图中,它的子项必须是可滚动的,否则将无法工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CollapsingToolbarLayout 并在滚动时隐藏工具栏 - CollapsingToolbarLayout and hide toolbar while scrolling 滚动片段工具栏应隐藏在android中 - While Scrolling Fragment toolbar should hide in android 如何在相对布局中有效滚动时隐藏工具栏? - How to hide toolbar while scrolling efficientliy in relativeLayout? 工具栏不会自动隐藏,在recyclerview中滚动时需要手动按下才能隐藏 - toolbar is not hiding automatically need to push manually to hide while scrolling in recyclerview 如何在 Web 视图中向下滚动时隐藏操作栏/工具栏 - How to Hide ActionBar/Toolbar While Scrolling Down in Webview Android:滚动时隐藏/显示工具栏不起作用 - Android: Hide/Show Toolbar while scrolling doesn't work 滚动RecyclerView时无法隐藏工具栏,可能是原因? - Unable to hide Toolbar while scrolling RecyclerView, possible cause? 如何在recyclelerView向下滚动时折叠后隐藏工具栏 - How to hide toolbar after collapsing while recyclerView scrolling down 工具栏下的GridView - 滚动时隐藏工具栏 - GridView under Toolbar - Hide ToolBar when Scrolling 屏幕滚动时隐藏和显示工具栏 - Hide and Show toolbar on scrolling of screen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM