Android – if you collapse backpressed, the toolbar disappears

When backpressed, my toolbar becomes invisible or disappears. This happens only when the toolbar is collapsed

>I have a recyclerview on the fragment > when I scroll the recycler, the toolbar will collapse > If I enter the next activity, called by some recyclers, and then press the back button, the toolbar will disappear. > If I scroll the recycler, the collapse will still occur, but the toolbar is not there, it is just a vertical space without any content

Fragment layout

<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>

Call layout on fragment

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

Some possible problems

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

resolvent:

Originally, my code was OK. The problem was caused by some errors on appcompat lib. I just updated the support library to version 22.2.1, and the problem disappeared

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'

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>