I'm trying to hide my toolbar in a RecyclerView scroll, and so far it seems to be hidden, but leaves it blank. I'm sure this has something to do with overlaying my MainActivity layout and fragment in FrameLayout.

Here is my activity_main.xml . I need FrameLayout, because I load different fragments with an item selection in the navigation drawer.
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/drawer" android:layout_width="match_parent" android:layout_height="match_parent" android:elevation="7dp" tools:context=".MainActivity" android:fitsSystemWindows="true"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include layout="@layout/toolbar" /> <FrameLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFFFFF" /> </LinearLayout> <android.support.design.widget.NavigationView android:id="@+id/navigation_view" android:layout_height="match_parent" android:layout_width="match_parent" android:layout_gravity="start" app:headerLayout="@layout/header" app:menu="@menu/drawer" /> </android.support.v4.widget.DrawerLayout>
And here is the code in the snippet that contains the RecyclerView.
... @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View v = inflater.inflate(R.layout.fragment_main, container, false); getActivity().setTitle("Unit One"); rv = (RecyclerView) v.findViewById(R.id.rv); rv.setHasFixedSize(true); llm = new LinearLayoutManager(getActivity()); rv.setLayoutManager(llm); initializeData(); initializeAdapter(); rv.addOnScrollListener(showHideToolbarListener = new RecyclerViewUtils.ShowHideToolbarOnScrollingListener(MainActivity.toolbar)); if (savedInstanceState != null) { showHideToolbarListener.onRestoreInstanceState((RecyclerViewUtils.ShowHideToolbarOnScrollingListener.State) savedInstanceState .getParcelable(RecyclerViewUtils.ShowHideToolbarOnScrollingListener.SHOW_HIDE_TOOLBAR_LISTENER_STATE)); } return v; } @Override public void onSaveInstanceState(Bundle outState) { outState.putParcelable(RecyclerViewUtils.ShowHideToolbarOnScrollingListener.SHOW_HIDE_TOOLBAR_LISTENER_STATE, showHideToolbarListener.onSaveInstanceState()); super.onSaveInstanceState(outState); }
And finally, the RecyclerView layout in fragment_main.xml :
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="8dp" android:paddingRight="8dp" android:orientation="vertical" android:scrollbars="vertical" android:id="@+id/rv" />
This is a continuation of my other post , but I wanted to ask a new question, since I'm trying a different method this time (do not read the whole post, see editing below). Here is its MainActivity and the actual scroll listener code .
I apologize if it seems to me that I say, βHere is my shit, correct it,β but I spent almost two hours looking for a possible solution to this. As always, I am very grateful for the help.
android android-fragments android-recyclerview toolbar
wasimsandhu
source share