滚动PreferenceFragment时如何隐藏工具栏?

时间:2016-11-11 03:21:00

标签: android android-fragments toolbar preferencefragment android-nestedscrollview

在我的Android应用中,我想在滚动Toolbar时隐藏PreferenceFragment

这是我的布局:

<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>

在我OnCreate的{​​{1}}中,我打电话给:

MainActivity

但它不起作用。仅显示第一行首选项(参见附图)。 enter image description here

如果我删除FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.content, MyPreferenceFragment.newInstance(), "fragment"); fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); fragmentTransaction.commit(); NestedScrollView,会正常显示,但滚动PreferenceFragmentToolbar将不会隐藏。

请帮助我!

0 个答案:

没有答案