How To Set Drawerlayout Below Toolbar With Coordinator Layout
I have an xml like this, when I show drawer layout, It overlays Toolbar, I want my drawerlayout below my Toolbar, I cannot figure out how to do it, I tried lots of stuff and I trie
Solution 1:
This works for me very well.. u need to have coordinator layout as parent layout and set layout behavior for ur drawer layout
<?xml version="1.0" encoding="utf-8"?><android.support.design.widget.CoordinatorLayoutxmlns: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.support.design.widget.AppBarLayoutandroid:id="@+id/appbar"android:layout_width="match_parent"android:layout_height="wrap_content"android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"><android.support.v7.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:background="?attr/colorPrimary"app:layout_scrollFlags="scroll|enterAlways"app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /></android.support.design.widget.AppBarLayout><!-- to make toolbar scroll and hide towards upside include this line
app:layout_behavior="@string/appbar_scrolling_view_behavior"--><android.support.v4.widget.DrawerLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:id="@+id/drawer_layout"android:layout_marginTop="?attr/actionBarSize"android:layout_width="match_parent"android:layout_height="match_parent"><!--<include layout="@layout/navigation_drawer_content"/>--><FrameLayoutandroid:id="@+id/content_frame"android:layout_width="match_parent"android:layout_height="match_parent" /><android.support.design.widget.NavigationViewandroid:id="@+id/nav_view"android:layout_width="wrap_content"android:layout_height="match_parent"android:layout_gravity="start"app:headerLayout="@layout/nav_header"app:menu="@menu/drawer_view" /></android.support.v4.widget.DrawerLayout></android.support.design.widget.CoordinatorLayout>
Solution 2:
I think it is too late but you may want to know what was the problem or what you could do.Anyways.
New Support Design Library
included NavigationDrawer
which you could use it like this answer : https://stackoverflow.com/a/34921695/4409113
<!-- 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" />
And this should work now after adding and editing some mistakes:
<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.DrawerLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:id="@+id/drawerLayout"android:layout_width="match_parent"android:layout_height="match_parent"><android.support.design.widget.CoordinatorLayoutandroid:id="@+id/root_coorinator"android:layout_width="match_parent"android:layout_height="match_parent"><android.support.design.widget.AppBarLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"><android.support.v7.widget.Toolbarandroid:id="@+id/toolBar"android:layout_width="match_parent"android:layout_height="?actionBarSize"app:layout_scrollFlags="scroll|enterAlways"app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"><TextViewandroid:id="@+id/toolBarTv"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="@string/app_name"android:textSize="18dp" /></android.support.v7.widget.Toolbar></android.support.design.widget.AppBarLayout><FrameLayoutandroid:id="@+id/frameLayout"android:layout_width="match_parent"android:layout_height="wrap_content"app:layout_behavior="@string/appbar_scrolling_view_behavior" /><android.support.design.widget.FloatingActionButtonandroid:id="@+id/fab"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="10dp"android:layout_marginEnd="10dp"app:elevation="4dp"app:fabSize="normal"app:layout_anchor="@id/root_coorinator"app:layout_anchorGravity="bottom|end|right" /></android.support.design.widget.CoordinatorLayout><!--<ScrollView
android:id="@+id/drawerList"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left|start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/mainTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="main"
android:textSize="18dp" />
</LinearLayout>
</ScrollView>--><!--Don't use it like that, Use NavigationDrawer instead--></android.support.v4.widget.DrawerLayout>
And one thing more, you could use that Toolbar
alone without adding that TextView
as a title.
Also, you could use that layout inside the NestedScrollView
.
Post a Comment for "How To Set Drawerlayout Below Toolbar With Coordinator Layout"