Android - Overflow Menu and Back Button not showing in Collapsing Toolbar -
i'm trying implement features new design support library create parallax scrolling toolbar looks similar new material design whatsapp profile pages. however, can't overflow menu , button show in top corners.
i have tried using following methods display button, none of them works.
getsupportactionbar().setdisplayhomeasupenabled(true); getsupportactionbar().sethomebuttonenabled(true); getsupportactionbar().setdisplayshowhomeenabled(true);
and overwriting oncreateoptionsmenu method overflow menu didn't work.
does know how add these toolbar icons collapsingtoolbar design support library? below layout xml activity. thanks!
<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_content" android:layout_width="match_parent" android:layout_height="match_parent" android:fitssystemwindows="true"> <android.support.design.widget.appbarlayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="256dp" android:theme="@style/themeoverlay.appcompat.dark.actionbar" android:fitssystemwindows="true"> <android.support.design.widget.collapsingtoolbarlayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_scrollflags="scroll|exituntilcollapsed" android:fitssystemwindows="true" app:contentscrim="@color/primary" app:expandedtitlemarginstart="48dp" app:expandedtitlemarginend="64dp"> <imageview android:id="@+id/backdrop" android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/headerbg" android:scaletype="centercrop" android:fitssystemwindows="true" app:layout_collapsemode="parallax" /> <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" app:popuptheme="@style/theme.appcompat.light.darkactionbar" app:layout_collapsemode="pin" /> </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:layout_gravity="fill_vertical" android:layout_marginbottom="?attr/actionbarsize" app:layout_behavior="@string/appbar_scrolling_view_behavior"> </android.support.v4.widget.nestedscrollview>
i had same issue, none existing answers have helped me, surprising fix of problem in question description.
solution appcompat activity
so working collapsing toolbar button needs few lines in controller oncreate
method:
//change id id toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); //this line shows button getsupportactionbar().setdisplayhomeasupenabled(true);
manifest of activity ( notice parentactivityname attribute ):
<activity android:name=".someactivity" android:parentactivityname=".mainactivity" android:theme="@style/apptheme.noactionbar"/>
template part:
<android.support.design.widget.appbarlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:fitssystemwindows="true" android:theme="@style/apptheme.appbaroverlay"> <android.support.design.widget.collapsingtoolbarlayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="200dp" app:layout_scrollflags="scroll|exituntilcollapsed" app:contentscrim="@color/colorprimary" android:fitssystemwindows="true" app:expandedtitlegravity="center_horizontal" > <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" android:background="@android:color/transparent" app:popuptheme="@style/themeoverlay.appcompat.light" app:layout_collapsemode="pin" /> </android.support.design.widget.collapsingtoolbarlayout> </android.support.design.widget.appbarlayout>
alternative solution ( appcompat activity )
controller oncreate
method:
toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); toolbar.setnavigationicon(android.support.v7.appcompat.r.drawable.abc_ic_ab_back_material); toolbar.setnavigationonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { onbackpressed(); } });
this approach uses same manifest , template presented in first solution.
Comments
Post a Comment