Navigation Drawer Below Tool Bar In Material Design
I want my drawer to open from the left below the tool bar. But, according to Material Design aspects that's not good. But still I want to do that. Here I have changed my XML file.
Solution 1:
I have created New XML file main_activity_appbar and added tool bar first and in same layout file I added my Drawer Layout. and in mainAcitity.java file I changed layout of that file.
main_activity_appbar.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><includeandroid:id="@+id/toolbar"layout="@layout/toolbar" /><android.support.v4.widget.DrawerLayoutxmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/drawer_layout"android:layout_width="match_parent"android:layout_height="match_parent"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><FrameLayoutandroid:id="@+id/container_body"android:layout_width="fill_parent"android:layout_height="0dp"android:layout_weight="1" /></LinearLayout><fragmentandroid:id="@+id/fragment_navigation_drawer"android:name="com.myApp.activity.FragmentDrawer"android:layout_width="@dimen/nav_drawer_width"android:layout_height="match_parent"android:layout_gravity="start"app:layout="@layout/fragment_navigation_drawer"tools:layout="@layout/fragment_navigation_drawer" /></android.support.v4.widget.DrawerLayout></LinearLayout>
MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_appbar);
This is working fine.
Solution 2:
Here is the latest solution for material design
<android.support.design.widget.AppBarLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"tools:openDrawer="start"><android.support.v7.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="@dimen/abc_action_bar_default_height_material"android:background="?attr/colorPrimary"android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/></android.support.design.widget.AppBarLayout><android.support.v4.widget.DrawerLayoutandroid:id="@+id/drawer_layout"android:layout_width="match_parent"android:layout_height="match_parent"><!--content_main is my layout you can design your own--><includelayout="@layout/content_main" /><FrameLayoutandroid:id="@+id/content"layout="@layout/content_main"android:layout_width="match_parent"android:layout_height="match_parent" /><!-- The navigation drawer --><android.support.design.widget.NavigationViewandroid:id="@+id/nav_view"android:layout_width="wrap_content"android:layout_height="match_parent"android:layout_gravity="start"app:menu="@menu/activity_main_drawer" /></android.support.v4.widget.DrawerLayout></LinearLayout>
Hope it helps
Post a Comment for "Navigation Drawer Below Tool Bar In Material Design"