0

Title says it all. The search view in this layout hides behind the toolbar and looks great.

The top level toolbar is the one supplied to the support actionbar The search view toolbar is just used as a view

The last item in the recyclerview loads more results and calls 'notifyItemRangeInserted'. Once you do that, the toolbar shadow disappears and when you scroll up, the search view is completely blank.

Any ideas why?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?android:actionBarSize" />

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="?android:listPreferredItemHeight"
            android:fitsSystemWindows="true">

            <android.support.v7.widget.Toolbar
                android:id="@+id/search_bar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="12dp"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:layout_marginTop="12dp"
                android:background="@drawable/search_background"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                app:contentInsetEnd="0dp"
                app:contentInsetLeft="0dp"
                app:contentInsetRight="0dp"
                app:contentInsetStart="0dp"
                app:layout_scrollFlags="scroll|enterAlways">

                <ImageView
                    android:id="@+id/search_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:paddingBottom="9dp"
                    android:paddingEnd="12dp"
                    android:paddingLeft="13dp"
                    android:paddingRight="12dp"
                    android:paddingStart="13dp"
                    android:paddingTop="9dp"
                    android:src="@drawable/search_icon" />

                <EditText
                    android:id="@+id/search_text"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/transparent"
                    android:focusable="true"
                    android:focusableInTouchMode="true"
                    android:fontFamily="@string/roboto_light"
                    android:gravity="center_vertical"
                    android:hint="@string/action_search"
                    android:imeOptions="actionGo"
                    android:maxLines="1"
                    android:minLines="1"
                    android:paddingBottom="9dp"
                    android:paddingTop="9dp"
                    android:textColor="#666666"
                    android:textSize="15sp" />
            </android.support.v7.widget.Toolbar>

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

        <android.support.v7.widget.RecyclerView
            android:id="@+id/search_results"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:paddingBottom="?android:listPreferredItemHeightSmall"
            android:paddingTop="4dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        <TextView
            android:id="@+id/search_results_count"
            android:layout_width="match_parent"
            android:layout_height="?android:listPreferredItemHeightSmall"
            android:layout_gravity="bottom"
            android:background="@color/light_gray"
            android:gravity="center"
            android:textColor="@color/medium_grey"
            tools:text="results results" />
    </android.support.design.widget.CoordinatorLayout>
</LinearLayout>
Psest328
  • 6,575
  • 11
  • 55
  • 90
  • Place the Toolbar inside AppBarLayout... wait! You have two of them! – Chisko Nov 23 '16 at 16:36
  • yeah... 1 is the toolbar supplied to the actionbar. The other is a toolbar view with an imageview and edittext that gets pushed up/down on scroll. I couldn't get the functionality with a linear layout as the search parent but it works with toolbar – Psest328 Nov 23 '16 at 16:38
  • well that's a functionality I've never heard of before. Why not put that in a LinearLayout? – Chisko Nov 23 '16 at 16:40
  • answered that before you even asked it, lol. see above :) – Psest328 Nov 23 '16 at 16:42
  • side note: even if the search view parent is changed from toolbar to linear layout... it still disappears – Psest328 Nov 23 '16 at 16:49
  • Can you post your Activity code as well ? – rhari Nov 23 '16 at 16:50
  • 1
    closing this issue. Turns out it's a known bug (https://code.google.com/p/android/issues/detail?id=178037). Solution can be found here: http://stackoverflow.com/questions/31084658/appbarlayout-layout-sometimes-invisible-once-it-enters-view-even-if-its-not?rq=1 – Psest328 Nov 23 '16 at 16:54

0 Answers0