【问题标题】:want to Implement WhatsApp like toolbar hide with DrawerLayout, NavigationView想要用 DrawerLayout、NavigationView 实现 WhatsApp 之类的工具栏隐藏
【发布时间】:2018-10-02 01:00:12
【问题描述】:

我正在使用,带有 NavigationView 的 DrawerLayout,带有此布局的 TabLayout 和 ViewPager TabLayout、ViewPager 和 NavigationBar 工作正常,但滚动效果不是我需要的。

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusableInTouchMode="true"
    tools:context=".MainActivity">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/main_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:elevation="6dp">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolBar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/green"
                android:minHeight="?attr/actionBarSize"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:elevation="0dp"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/toolBar"
                android:background="@color/green"
                android:minHeight="?attr/actionBarSize"
                app:elevation="0dp"
                app:tabIndicatorColor="@color/white"
                app:tabIndicatorHeight="2dp"
                app:tabMode="scrollable"
                app:tabSelectedTextColor="@color/white"
                app:tabTextColor="@color/textColor" />

        </android.support.design.widget.AppBarLayout>

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

    </android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/navigationView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true">

        <include
            android:id="@+id/navigationItem"
            layout="@layout/drawer_layout" />
    </android.support.design.widget.NavigationView>

</android.support.v4.widget.DrawerLayout>

但我不知道我错过了什么一切正常,但滚动时主工具栏没有隐藏。 Activity 文件有什么变化吗? 请帮我解决这个问题

【问题讨论】:

    标签: android xml layout hide toolbar


    【解决方案1】:

    Implementation 'com.android.support:design:27.1.1' 设计库添加到您的 Gradle 依赖项中。不要忘记在 AppBarLayout 之后添加 NestedScrollView

    这里是 NestedScrollView 示例。

    <android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="fill_vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/></android.support.v4.widget.NestedScrollView>
    

    【讨论】:

    • 我正在使用实现 'com.android.support:design:27.1.1' 但我想在单击 NavigationBar 时打开新 Activity。建议另一种解决方案。
    • 您可以通过在导航栏(ActionBar)按钮的 onClick() 方法上传递 Intent 来打开一个新 Activity。有关实施细节,您可以关注link
    • 请检查我的答案。 .
    • 干得好 Nitish,正如我所指出的,您确实实现了 NestedScrollView,这在这种情况下是必不可少的。
    【解决方案2】:

    我已经使用

    <android.support.v4.widget.NestedScrollView
                android:id="@+id/nest_scrollview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/tabLayout"
                android:fillViewport="true"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                tools:context=".Activity.MainActivity"
                tools:showIn="@layout/activity_main">
    
                <android.support.v4.view.ViewPager
                    android:id="@+id/viewPager"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
    
            </android.support.v4.widget.NestedScrollView>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-13
      • 2015-03-01
      • 1970-01-01
      • 2012-02-10
      • 1970-01-01
      • 1970-01-01
      • 2018-02-22
      • 2023-03-26
      相关资源
      最近更新 更多