【问题标题】:Toolbar disappear when backPressed if collapsed如果折叠,则工具栏在 backPressed 时消失
【发布时间】:2015-07-21 02:08:36
【问题描述】:

我的工具栏在按下后变得不可见或消失。仅当工具栏折叠时才会出现这种情况。

  1. 我在片段上有一个 RecyclerView
  2. 当我滚动回收站时,工具栏会折叠
  3. 如果我进入下一个活动,由一些回收站调用,然后按返回按钮,工具栏就会消失。
  4. 如果我滚动回收器,折叠仍然会发生,但工具栏不存在,只是一个没有任何内容的垂直空间。

片段布局

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

  <android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">


        <!--Toolbar-->
        <android.support.v7.widget.Toolbar
            style="@style/mytoolbar_details"
            android:id="@+id/toolbar"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            android:background="@color/theme_primary"
            app:layout_collapseMode="none" />

    <!--Toolbar Sort-->
    <android.support.v7.widget.Toolbar
        style="@style/mytoolbar_details"
        android:id="@+id/toolbar_sort"
        android:title="Toolbar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:background="@color/theme_primary_dark"
        android:visibility="gone"
        app:layout_collapseMode="pin" />

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

  <android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/fragment_tasklist_recyclerview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

  <!--ADD Fragment Container-->
  <RelativeLayout
    android:id="@+id/add_container"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true"
    android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>

在 Fragment 上调用布局

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    fragmentView    = inflater.inflate(R.layout.tasklist_fragment, container, false);

一些可能的问题

W/View﹕ requestLayout() improperly called by android.support.v7.widget.Toolbar{335f934 V.E..... ......ID 0,0-1080,168 #7f0d009c app:id/toolbar} during layout: running second layout pass

W/View﹕ requestLayout() improperly called by android.support.design.widget.CollapsingToolbarLayout{3c2cf991 V.ED.... ......I. 0,0-1080,420 #7f0d009a app:id/collapsing_toolbar} during second layout pass: posting in next frame

【问题讨论】:

    标签: android toolbar android-recyclerview android-coordinatorlayout


    【解决方案1】:

    原来我的代码没问题。 该问题是由 appcompat 库中的一些错误引起的。我刚刚将支持库更新到 22.2.1 版本,问题就消失了。

    compile "com.android.support:appcompat-v7:22.2.1"
    compile "com.android.support:support-annotations:22.2.1"
    compile "com.android.support:design:22.2.1"
    compile 'com.android.support:recyclerview-v7:22.2.1'
    compile 'com.android.support:cardview-v7:22.2.1'
    

    【讨论】:

      【解决方案2】:

      目前仅适用于设计支持库 v22.2.1 https://code.google.com/p/android/issues/detail?id=183333

      【讨论】:

        猜你喜欢
        • 2015-12-28
        • 2017-02-27
        • 2017-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多