How to make toolbar visible again which is previous hidden using layout_scrollFlags, when swipe to different viewpager page

you can do it like this :

final AppBarLayout appBarLayout = view.findViewById(R.id.app_bar_layout);
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            if (position == 1)
                appBarLayout.setExpanded(true, true);
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

so when viewPager is in unscrollable page it expands and toolbar appears


@Marzieh Heidari answer is the correct answer for this question, but I share my different approach that I use in my project to solve this problem.

In the fragment which have short content, I still keep NestedScrollView at root. Then I still able to scroll up/down to collapse and expand toolbar

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:isScrollContainer="false"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="This fragment have short content"
            android:textSize="100sp"
            />
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

Hope it help