Android Toolbar + Tab Layout + Drawer, Hide toolbar when scrolling and take TabLayout to the top

后端 未结 10 934
遇见更好的自我
遇见更好的自我 2020-12-28 14:41

I have activity which has drawer attached to it. Each menu of the drawer is a fragment, and under one of the menu I have a fragment with TabLayout, and each tab

相关标签:
10条回答
  • 2020-12-28 15:28

    To hide your Toolbar anytime you can use :

    getSupportActionBar().hide();
    

    for more explanation view url1 or url2

    0 讨论(0)
  • 2020-12-28 15:31

    Remove coordinator layout used in tabbed activity. Use LinearLayout

    0 讨论(0)
  • 2020-12-28 15:34

    You can try the following one, which I have used to hide the toolbar, and make the scrollview take the whole screen for full page reading in my application design.

    It is as follows.

    1. Hide the toolbar.
    2. Get your phone screen width and Height.
    3. Store the Tab layout Height and width to a temporary variable.
    4. Assign the phone screen width and Height to your Tab Layout.

    This can be done in the following way:

    getSupportActionBar().hide();    
    int mwidth = getApplicationContext().getResources().getDisplayMetrics().widthPixels;
    int mheight = getApplicationContext().getResources().getDisplayMetrics().heightPixels;
    temp = (TabLayout) myfrag.getActivity().findViewById(R.id.TabLayout_genesis);
    int getwidth = temp.getWidth();
    int getheight = temp.getHeight();
    temp.setMinimumHeight(mheight);
    temp.setMinimumWidth(mwidth);
    

    Hope it helps.

    0 讨论(0)
  • 2020-12-28 15:37

    Can you use the support design library? It has this behavior built in to do exactly what you have described. It uses CoordinatorLayout to accomplish this.

    <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:animateLayoutChanges="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/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.view.ViewPager
            android:id="@+id/tabanim_viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    
        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_alarm_add_white_48dp"
            app:layout_anchor="@id/tabanim_viewpager"
            app:layout_anchorGravity="bottom|right|end"
            android:layout_margin="16dp"
            />
    
    </android.support.design.widget.CoordinatorLayout>
    
    0 讨论(0)
提交回复
热议问题