【问题标题】:Toolbar collapse on Scroll does not work滚动上的工具栏折叠不起作用
【发布时间】:2016-03-24 21:32:45
【问题描述】:

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

我的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 上,但没有成功。

我做错了什么??

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

提前致谢!

【问题讨论】:

  • 尝试将android:fitsSystemWindows="true" 添加到您的AppBarLayout
  • @razzledazzle 您好,感谢您的评论!我试过了,但它只从头开始推动状态栏下的应用栏(不滚动):-/

标签: android android-layout


【解决方案1】:

这是 Android 设计支持库 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

【讨论】:

  • 如果这解决了您的问题,您应该接受自己的答案。
  • @Marko 会的! :) 我只需要等到明天(系统还不让我这样做)
  • 哦...我的错,我没有意识到这一点:)
猜你喜欢
  • 2015-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-26
相关资源
最近更新 更多