0

In my Android app, I want to hide the Toolbar when I scroll the PreferenceFragment.

Here is my 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <android.support.v7.widget.Toolbar
        android:id="@+id/tabanim_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    <android.support.design.widget.TabLayout
        android:id="@+id/tabanim_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    >
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/content"
        android:background="#ea3232"/>
</android.support.v4.widget.NestedScrollView>

And in OnCreate of MainActivity I call:

FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
  fragmentTransaction.replace(R.id.content, MyPreferenceFragment.newInstance(),
          "fragment");
  fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
  fragmentTransaction.commit();

But it doesn't work. Only first row of preference is shown (see attached image). enter image description here

If I remove NestedScrollView, the PreferenceFragment is shown normally, but the Toolbar will not hidden when I scroll the PreferenceFragment.

Please help me!

TOP
  • 2,574
  • 5
  • 35
  • 60

0 Answers0