Android: showing bookmarks when toolbar is displayed

This is whatsapp when you do not scroll up. The toolbar is displayed and a tab is located below it.

Screenshot1:

whatsapp1

This is whatsapp as soon as you scroll it. You can see that the toolbar is hidden.

screenshot2:

whatspp2

There is a guide showing how to create this effect. I followed him and got this effect to work in my application.

https://mzgreen.imtqy.com/2015/06/23/How-to-hideshow-Toolbar-when-list-is-scrolling(part3)/

link from the manual

, , , , SCREENSHOT1. , , , . , .

xml, , https://github.com/mzgreen/HideOnScrollExample/blob/master/app/src/main/res/layout/activity_part_three.xml. :

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                                 xmlns:app="http://schemas.android.com/apk/res-auto"
                                                 android:id="@+id/coordinatorLayout"
                                                 android:layout_width="match_parent"
                                                 android:layout_height="match_parent">
    <android.support.design.widget.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

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

        <android.support.design.widget.TabLayout
                android:id="@+id/tabLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:tabTextColor="@android:color/white"
                app:tabSelectedTextColor="@android:color/white"
                app:tabIndicatorColor="@android:color/white"
                app:tabIndicatorHeight="6dp"/>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
            android:id="@+id/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/fabButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end|bottom"
            android:layout_margin="@dimen/fab_margin"
            android:src="@drawable/ic_favorite_outline_white_24dp"
            app:borderWidth="0dp"
            app:layout_behavior="pl.michalz.hideonscrollexample.ScrollingFABBehavior"/>

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

- , , ?

EDIT:

tablayouts, tablayouts , snackbar , . , snackbars , , , , 3 , .

xml :

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/snackbarPosition">

    <android.support.v4.widget.SwipeRefreshLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/swipeContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/my_recycler_view"
                android:layout_below="@+id/join"
                android:scrollbars="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
            </android.support.v7.widget.RecyclerView>

    </RelativeLayout>

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

</android.support.design.widget.CoordinatorLayout>
+4
3

. viewPager , . :

Snackbar snackbar = Snackbar.make(findViewById(R.id.viewPager), "Your Message", Snackbar.LENGTH_LONG);
    snackbar.getView().setBackgroundColor(Color.parseColor("#00b8ba"));
    snackbar.show();

, findViewById (R.id.viewPager) .

, viewPager :

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

( ):

Snackbar snackbar = Snackbar.make(getView(), "First", Snackbar.LENGTH_LONG);
        snackbar.getView().setBackgroundColor(Color.parseColor("#00b8ba"));
        snackbar.show();

:

Snackbar snackbar = Snackbar.make(getView(), "Second", Snackbar.LENGTH_LONG);
        snackbar.getView().setBackgroundColor(Color.parseColor("#00b8ba"));
        snackbar.show();
+2

ViewPagers wrap_content.

Layout , match_parent.

, , Layout Snackbar.make.

:

, , , Layout , .

CoordinatorLayouts , , child CoordinatorLayouts , .

-, Layouts ​​ Snackbar.make . ( ), Layout .

, , , static , Snackbar , .

- , Snackbar , , , . , .

+2

, , , .

.

:

    coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorlayout);
    TestFragment testFragment = new Fragment();

    //Needed for every fragment
    testFragment.setActivityCoordinatorLayout(coordinatorLayout); //passed the activity coordinatorlayout to my fragment.

:

public void setActivityCoordinatorLayout(CoordinatorLayout activityCoordinatorLayout) {
    this.activityCoordinatorLayout = activityCoordinatorLayout;
}

snackbar :

            Snackbar.make(activityCoordinatorLayout, "No internet", Snackbar.LENGTH_LONG)
                    .setAction("Retry", new View.OnClickListener() {
                        @Override
                        public void onClick(View v) { <YOUR CODE>}}).show();

, , . - Nilesh getView.

+1
source

Source: https://habr.com/ru/post/1622250/


All Articles