Android design support navigation drawer huge actionbar -
i implementing design support navigation drawer , got working, problem toolbar huge, extends on entire activity height.
the code using: activity_main:
<android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/drawer_layout" android:layout_height="match_parent" android:layout_width="match_parent" android:fitssystemwindows="true"> <include android:id="@+id/toolbar" layout="@layout/toolbar" /> <framelayout android:id="@+id/frame_container" android:layout_width="match_parent" android:layout_height="match_parent" /> <android.support.design.widget.navigationview android:id="@+id/nav_view" android:layout_height="match_parent" android:layout_width="wrap_content" android:layout_gravity="start" android:fitssystemwindows="true" app:headerlayout="@layout/navigation_header" app:menu="@menu/drawer_view"/> </android.support.v4.widget.drawerlayout>
toolbar:
<android.support.v7.widget.toolbar 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="?attr/actionbarsize" android:background="?attr/colorprimary" android:elevation="4dp" android:fitssystemwindows="true" app:popuptheme="@style/menuoverlay" />
mainactivity:
public class mainactivity extends appcompatactivity { private drawerlayout mdrawerlayout; public static toolbar toolbar; public static fragmentmanager supportfragmentmanager; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); setuptoolbar(); setupnavdrawer(); mdrawerlayout = (drawerlayout) findviewbyid(r.id.drawer_layout); navigationview navigationview = (navigationview) findviewbyid(r.id.nav_view); if (navigationview != null) { setupdrawercontent(navigationview); } } @override public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.menu_main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case android.r.id.home: mdrawerlayout.opendrawer(gravitycompat.start); return true; } return super.onoptionsitemselected(item); } private void setupdrawercontent(navigationview navigationview) { navigationview.setnavigationitemselectedlistener(new navigationview.onnavigationitemselectedlistener() { @override public boolean onnavigationitemselected(menuitem menuitem) { menuitem.setchecked(true); mdrawerlayout.closedrawers(); return true; } }); } private void setuptoolbar() { toolbar = (toolbar) findviewbyid(r.id.toolbar); if (toolbar != null) { setsupportactionbar(toolbar); } } private void setupnavdrawer() { if (toolbar != null) { getsupportactionbar().setdisplayhomeasupenabled(true); toolbar.setnavigationicon(r.drawable.ic_menu); toolbar.setnavigationonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { mdrawerlayout.opendrawer(gravitycompat.start); } }); } } }
the main content view must first child inside drawerlayout
, have change activity_main
layout to:
<android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/drawer_layout" android:layout_height="match_parent" android:layout_width="match_parent" android:fitssystemwindows="true"> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include android:id="@+id/toolbar" layout="@layout/test_toolbar" /> <framelayout android:id="@+id/frame_container" android:layout_width="match_parent" android:layout_height="match_parent" /> </linearlayout> <android.support.design.widget.navigationview android:id="@+id/nav_view" android:layout_height="match_parent" android:layout_width="wrap_content" android:layout_gravity="start" android:fitssystemwindows="true" app:headerlayout="@layout/navigation_header" app:menu="@menu/drawer_view"/> </android.support.v4.widget.drawerlayout>
Comments
Post a Comment