android - 滚动时工具栏折叠不起作用

标签 android android-layout

我想让工具栏在向下滚动时折叠,但它不起作用..

我的activity.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=.reviews.ReviewListActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

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

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

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?android:attr/actionBarSize"
        android:background="@color/bgLightGrey"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView
            android:id="@+id/textNothingMessage"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="48dp"
            android:gravity="top|center_horizontal"
            android:text="@string/msg_no_reviews"
            android:textColor="@color/secondaryText"
            android:textSize="24sp"
            android:visibility="invisible" />

        <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/layoutSwipeRefresh"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerViewReviews"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

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

    </FrameLayout>

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

我的styles.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>


<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/splash</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>

<style name="AppTheme.StartTheme">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.NoActionBar">
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

我的AndroidManifest.xml

    <activity
        android:name=".reviews.ReviewListActivity"
        android:label="@string/title_activity_review_list"
        android:parentActivityName=".MainActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".MainActivity" />
    </activity>

它确实有点崩溃......以一种奇怪的方式。 Toolbar 向上移动并进入系统状态栏下方,但工具栏本身不会折叠。叹息...

我尝试将 app:layout_behavior 属性放在 RecyclerView 上,但没有成功。

我做错了什么?

我怀疑 Theme,但我在添加新 Activity 时使用的是 Android Studio 创建的默认主题。

提前致谢!

最佳答案

这是 Android Design Support Library 23.2.0 的一个错误。

我已将其更新到 23.2.1,它解决了问题。

app.gradle中添加或替换行

compile 'com.android.support:support-v4:23.2.1'
compile 'com.android.support:design:23.2.1'

引用:https://stackoverflow.com/a/36006211/4694036

关于android - 滚动时工具栏折叠不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36191479/

相关文章:

javascript - Phonegap 构建应用程序中未定义的 Phonegap 函数 - pushNotifications 也不起作用

android - 作为 fragment 子对象的空对象

android - 如何在约束布局中动态设置权重

Android 自定义选项卡内容

Android Textview 文本大小由 XML 和 Java 设置不同

android - 从当前位置到已知位置的谷歌方向路线

Android,无法隐式启动 Activity

android - 为什么 getBitmap 方法不起作用?

android - Android 2.2 中的设备管理应用程序

android小部件 TextView 字幕滚动