0

I want gone toolbar Menu when collapsed appBarlayout, but I don't know how can it.
My code is here:

    public class MainFragment extends BaseFragment implements Toolbar.OnMenuItemClickListener ... 

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

...
}
    @Override
    public int getMenu() {
        return R.menu.search;
    }

XML codes :

<android.support.design.widget.CoordinatorLayout
    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:fitsSystemWindows="true"
    tools:context="com.sepandar.xengine.fragment.MainFragment">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimaryDark"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <com.sepandar.xengine.views.XTabLayout
                android:id="@+id/xTab"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                app:tabMode="scrollable"/>

            <com.api.common.widget.MyToolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@android:color/transparent"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:theme="@style/ToolBarStyle"/>

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

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

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/xTab"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <com.nt.googleplaysearch.views.SearchView
        android:id="@+id/search"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="invisible"
        app:layout_collapseMode="pin"/>

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

I want when Collapsed appBarLayout, gone public int getMenu(), and when expand show this public int getMenu().

How can I it?

Pro
  • 11
  • 2

2 Answers2

0

Use AppBarLayout.OnOffsetChangedListener to get appbar status {expand/collapse}, Then hide appbar menu on offset value change.

Ashu
  • 1
  • 2
0

use this app:layout_scrollFlags="scroll|enterAlways" insted of app:layout_scrollFlags="scroll|exitUntilCollapsed" in MyToolbar it was work with RecyclerView or NestedScrollView as second element in CoordinatorLayout wrap your ViewPager in NestedScrollView

Rajesh
  • 2,618
  • 19
  • 25