0

I have added a toolbar and i'm trying to use the hide and show feature on scroll of toolbar but for some reason it is not working i followed every step from tutorial still it is not working. I'm using toolbar in a fragment so maybe that is aslo a reason but i do not know much about it. so i would appreciate some help

xml

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

    <!-- AppBarLayout is a wrapper for a Toolbar in order to apply scrolling effects. -->
    <!-- Note that AppBarLayout expects to be the first child nested within a CoordinatorLayout -->
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

        <!-- Toolbar is the actual app bar with text and the action items -->
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:titleTextColor="@color/White"
            app:layout_scrollFlags="scroll|enterAlways|snap">
            <com.ct.listrtrial.Custom.CustomTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Feeds"
                android:textSize="30sp"
                android:textColor="@color/White"
                android:layout_gravity="center"
                android:id="@+id/toolbar_title"
                android:layout_marginRight="@dimen/_200sdp"/>
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>

    <!-- This could also be included from another file using the include tag -->
    <!-- i.e `res/layout/content_main.xml` -->
    <!-- `app:layout_behavior` is set to a pre-defined standard scrolling behavior -->

    <android.support.v7.widget.RecyclerView
        android:id="@+id/feed_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

   <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_anchorGravity="bottom|center"
        android:layout_marginBottom="5dp"
       android:layout_gravity="end|bottom"
       android:src="@drawable/ic_search_black_24dp" />

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

Fragment code

toolbar = (Toolbar)view.findViewById(R.id.toolbar);
        ((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
        CustomTextView customTextView = (CustomTextView)toolbar.findViewById(R.id.toolbar_title);
        //getActivity().getTitle();
        ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);

2 Answers2

0

if you want to hide and show tool bar when scrolling then Replace your toolbar flag with.

app:layout_scrollFlags="scroll|enterAlwaysCollapsed|snap">
0

add below code in your fragment onCreateView

ViewCompat.setNestedScrollingEnabled(recyclerView, true);

I think this will help you.

Md Jubayer
  • 272
  • 3
  • 13