Toolbar not displayed from the inner minimize panel

Here is the code.

<?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/main" android:layout_height="match_parent" android:layout_width="match_parent"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="100dp"> <android.support.design.widget.CollapsingToolbarLayout android:layout_width="match_parent" android:layout_height="match_parent" app:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed"> <android.support.v7.widget.Toolbar android:id="@+id/mytoolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:title="@string/app_name" app:layout_collapseMode="pin" app:theme="@style/ThemeOverlay.AppCompat.Light"/> <android.support.design.widget.TabLayout android:id="@+id/main_tablayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" app:layout_collapseMode="none"/> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <!--<android.support.v4.widget.NestedScrollView--> <!--android:id="@+id/nestedscroll"--> <!--android:layout_width="match_parent"--> <!--android:layout_height="match_parent"--> <!--android:fillViewport="true"--> <!--android:scrollbars="horizontal"--> <!--app:layout_behavior="@string/appbar_scrolling_view_behavior">--> <android.support.v4.view.ViewPager android:id="@+id/main_viewpager" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"/> <!--</android.support.v4.widget.NestedScrollView>--> <android.support.design.widget.FloatingActionButton android:id="@+id/main_fab" android:layout_margin="16dp" android:src="@android:drawable/ic_media_play" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_anchor="@id/main_viewpager" app:layout_anchorGravity="bottom|end"/> </android.support.design.widget.CoordinatorLayout> 

Problem:
1) The toolbar is not displayed.
2) Folding the toolbar does not collapse at all. [SOLVED]
3) Viewpager and FAB are also not visible if placed inside nestedScrollView. [Solvable]

Additional Information:
The layout for the Viewpager fragments has Linringayout as root and inside which there is a recyclerview.

Everything seems to be ok with the code. It is impossible to understand what is missing. A good explanation of how coordinators and folding toolbars work will also really help.

+5
source share
2 answers

1) The toolbar is not displayed.

First of all, you need to determine which toolbar you want to use in your activity class:

  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); 

Modify existing xml code:

  <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorPrimary" app:title="@string/app_name" app:layout_collapseMode="parallax"> </android.support.v7.widget.Toolbar> 

in

  <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" //set initial height app:popupTheme="@style/ThemeOverlay.AppCompat.Light" //this might be also useful app:title="@string/app_name" app:layout_collapseMode="parallax" /> 

2) Collapsing the toolbar does not collapse at all.

Has your activity been used correctly. Install on your AppBarLayout :

 android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 

like in this example: include_list_viewpager.xml

3) Viewpager and FAB are also not visible if placed inside nestedScrollView.

There is no reason for this. Adding these lines:

 android:layout_marginTop="?attr/actionBarSize" app:layout_behavior="@string/appbar_scrolling_view_behavior" 

Up ViewPager should be enough.

Both of these must be direct children of the CoordinatorLayout .

Follow this example: http://blog.nkdroidsolutions.com/collapsing-toolbar-with-tabs-android-example/

If you are new to Material Design or feel a little lost with some of his behavior, I highly recommend checking out the Chris Banes Material Design cheesequare design cheesequare : https://github.com/chrisbanes/cheesesquare/

Hope this helps

+4
source

First of all, you should tell your activity which toolbar you are using, so in the onCreate method you should have:

  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); 

your second and third problems must be addressed together. You should use NestedScrollView as the main layout for the fragments inside the ViewPager, and then inside this, put a LinearLayout or something else.

+2
source

All Articles