简体   繁体   中英

How to hide toolbar in a fragment?

I have a Main toolbar for the app... and as usual a fragment pager... but in one of my fragments I have a CollapsingToolbar as well. So,

how do I hide the main toolbar and the fragment pager toolbar when I collapse this toolbar?

XML CODE

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:src="@drawable/profilepic"
            android:id="@+id/profilePic"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.7" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin">


        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">


    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/a"
        android:gravity="center_horizontal"
        android:orientation="vertical">

        <TextView
            android:id="@+id/name"
            android:layout_width="70dp"
            android:layout_height="30dp"
            android:layout_marginTop="12dp"
            android:text="Name"
            android:textColor="@color/white"
            android:textSize="20dp" />

        <TextView
            android:id="@+id/status"
            android:layout_width="70dp"
            android:layout_height="30dp"
            android:layout_marginTop="45dp"
            android:text="Status"
            android:textColor="@color/silver"
            android:textSize="20dp" />

        <TextView
            android:id="@+id/email"
            android:layout_width="70dp"
            android:layout_height="30dp"
            android:layout_marginTop="21dp"
            android:text="Email"
            android:textSize="20dp" />

        <TextView
            android:id="@+id/quote"
            android:layout_width="70dp"
            android:layout_height="30dp"
            android:layout_marginTop="27dp"
            android:text="Quote"
            android:textSize="20dp" />

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Number"
            android:textSize="20dp" />

    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

You can use differents ways. Try this:

onCreate method call:

((AppCompatActivity) getActivity()).getSupportActionBar().hide(); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM