android - 滚动时工具栏不隐藏

标签 android xml

尝试使用 appbar_scrolling_view_behavior + 滚动标志隐藏 ListView 滚动上的工具栏,但没有结果,这是 xml 代码,无法理解这有什么问题

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.lol.materialdesigntest.MainActivity">

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

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@android:color/holo_orange_light"
            app:layout_scrollFlags="scroll|enterAlways"/>

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

    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_anchor="@id/list_view"
        app:layout_anchorGravity="bottom|right"
        android:src="@mipmap/ic_launcher"
        android:layout_margin="15dp"/>

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

最佳答案

默认情况下,ListView 没有启用嵌套滚动。使用

ViewCompat.setNestedScrollingEnabled(listView, true);

启用它。

请注意,这将从 lollipop 开始。如果你想支持旧版本的 android,你应该使用 RecyclerView

关于android - 滚动时工具栏不隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43469433/

相关文章:

java - 在 Java 中生成 XSD 文件

xml - 十六进制 0X19 是无效字符

Android Maps V2 内存泄漏三星设备

android - 任务 :app:uploadCrashlyticsMappingFileRelease FAILED Expected file collection to contain exactly one file, 但是,它不包含文件

javascript - 对 JSON 的 SOAP 响应 (XML)

android - 使用 XML 中的 "animateLayoutChanges"属性对布局进行动画处理

Android Lollipop 应用程序没有响应

Android Spinner 错误 : android. view.WindowManager$BadTokenException: 无法添加窗口

java - Android应用程序: how to use the camera and grab the image bytes?

sql-server - 在具有切碎/扁平 xml 字段的大表上更快地选择