Not able to do Navigation Drawer Below toolbar - android

How to fit the Navigation Drawer under toolbar it's overlaps the main layout.
activity_set_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns: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"
android:orientation="vertical"
android:fitsSystemWindows="true"
tools:openDrawer="start"
>
<include
layout="#layout/app_bar_set_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#000000"
android:layout_marginTop="?android:attr/actionBarSize"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:itemTextColor ="#FFFFFF"
app:headerLayout="#layout/nav_header_set_main"
app:menu="#menu/activity_set_main" />
</android.support.v4.widget.DrawerLayout>
app_bar_set_main.xml
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.pash.icas_nvod.setMain">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
>
<ImageView
android:layout_width="220dp"
android:layout_height="40dp"
android:src="#drawable/bydesign_logo"
android:layout_marginRight="80dp"
android:id="#+id/toolbar_title" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_set_main" />
</android.support.design.widget.CoordinatorLayout>
content_set_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/content_set_main_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#EE7F22"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.pash.icas_nvod.setMain"
>
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
</RelativeLayout>
Above are my xml files am not able make drawer fit under the toolbar.
The drawer layout is overlapping to main layout. How to i resolve it..?
I have searched alot but none of the answer relates to my problem.Thank you in advance.

You can try android:layout_below="#+id/app_bar_set_main" in your DrawerLayout.
-----OR-----
You can try to move your toolbar out of your drawerlayout. So in my project, i used LinearLayout as root layout. I tried to replace with your components, hope it helps.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<include
layout="#layout/app_bar_set_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true"
tools:openDrawer="start"
>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_below="#+id/app_bar_set_main" //Add this line also.
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#000000"
android:layout_marginTop="?android:attr/actionBarSize"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:itemTextColor ="#FFFFFF"
app:headerLayout="#layout/nav_header_set_main"
app:menu="#menu/activity_set_main" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
Edit: Also you must add android:layout_below to fit your drawer under toolbar.

Related

How to push admob ads behind navigation drawer?

I have added admob ads on the project with navigation drawer. I want the admob ads to be pushed behind the drawer. I have used following xml code but it does not work perfectly.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_alignParentBottom="true"
android:id="#+id/bannerAdLayout">
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-xxx/yyy"
/>
</LinearLayout>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_above="#+id/bannerAdLayout"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:itemIconTint="#000000"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
Please see the attached picture.
here is your solution.
you need to remove Adview from this file and just add that file in
your app_bar_main layout
UPDATE
here is my
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns: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"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginTop="?actionBarSize"
android:background="#drawable/bg"
app:itemTextAppearance="#style/NavigationDrawerStyle"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
here is my app_bar_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/realative"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/appBarLayout"
>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-xxx/yyy"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>

Handle both NavigationView and page content

My NavigationView is displayed behind the page content. So I tried to use bringToFronton my NavigationView : the page content goes behind the NavigationView, BUT becomes unclickable/unscrollable (page content is a recyclerView with multiple items).
How can I handle both NavigationView and page content ?
Even when the NavigationView is closed, the RecyclerView is unclickable/unscrollable
Here is my layout file :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/background_color">
<include android:id="#+id/mytoolbar"
layout="#layout/toolbar"/>
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_below="#+id/mytoolbar"
>
<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:menu="#menu/drawer_menu_planvente"/>
</android.support.v4.widget.DrawerLayout>
<RelativeLayout
android:id="#+id/layoutPlanVente"
android:layout_below="#+id/mytoolbar"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewProduitsVente"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:scrollbarSize="50dp"
android:orientation="vertical">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
</RelativeLayout>
Update your layout as below:
<?xml version="1.0" encoding="utf-8"?>
<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">
<!-- Content -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include android:id="#+id/mytoolbar"
layout="#layout/toolbar"/>
<RelativeLayout
android:id="#+id/layoutPlanVente"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewProduitsVente"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:scrollbarSize="50dp" />
</RelativeLayout>
</LinearLayout>
<!-- Navigation -->
<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:menu="#menu/drawer_menu_planvente" />
</android.support.v4.widget.DrawerLayout>
Inspired by FAT answer i made it work with this layout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/background_color">
<include android:id="#+id/mytoolbar"
layout="#layout/toolbar"/>
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_below="#+id/mytoolbar"
>
<RelativeLayout
android:id="#+id/layoutPlanVente"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewProduitsVente"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:scrollbarThumbVertical="#drawable/scrollbar_custom"
android:orientation="vertical">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
<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:menu="#menu/drawer_menu_planvente"/>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>

Android - Navigation Drawer and NavigationBar

i implemented a navigation bar at the bottom of my activity
now i need to implement a navigationdrawer too
how do i do?
here is my layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:design="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="app.movemate.MainActivity"
android:orientation="vertical"
android:layout_weight="1">
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/transparent">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:background="#color/colorPrimary"
android:id="#+id/navigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
design:menu="#menu/menu_navigation"
android:layout_gravity="bottom"
design:itemIconTint="#color/White"
design:itemTextColor="#color/White"
design:itemBackground="#drawable/navigation_selected_item"/>
</LinearLayout>
i tried with this tutorial https://www.youtube.com/watch?v=mtOztjHmM0c
but when i compile it says i already have a navigation bar
EDIT
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:design="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="app.movemate.MainActivity"
android:orientation="vertical"
android:layout_weight="1">
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/transparent"
android:layout_alignParentTop="true">
</FrameLayout>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:layout_height="match_parent"
android:layout_width="match_parent"
layout="#layout/navigation_view"/>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="#menu/menu_navigation"
android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>
<android.support.design.widget.BottomNavigationView
android:background="#color/colorPrimary"
android:id="#+id/navigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
design:menu="#menu/menu_navigation"
android:layout_gravity="bottom"
design:itemIconTint="#color/White"
design:itemTextColor="#color/White"
design:itemBackground="#drawable/navigation_selected_item"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
i tried this and i can see the navbar at bottom but the fragment is covered by drawer background
suggestions?
EDIT - SOLVED
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:design="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="app.movemate.MainActivity"
android:orientation="vertical"
android:layout_weight="1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:layout_height="match_parent"
android:layout_width="match_parent"
layout="#layout/navigation_view"/>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/navigationView"
android:background="#color/White"
android:layout_alignParentTop="true">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:background="#color/colorPrimary"
android:id="#+id/navigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
design:menu="#menu/menu_navigation"
android:layout_gravity="bottom"
design:itemIconTint="#color/White"
design:itemTextColor="#color/White"
design:itemBackground="#drawable/navigation_selected_item"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
design:menu="#menu/menu_navigation"/>
</android.support.v4.widget.DrawerLayout>
if you want to create navigation drawer u should use drawerLayout.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns: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"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<FrameLayout
layout="#layout/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:backgroundTint="#color/white"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:itemBackground="#color/white"
app:itemIconTint="#color/black"
app:itemTextColor="#color/black"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
in android studio, Navigation bar and navigation layout automatically gets added once you create a new activity from templates "navigation drawer activity"

How to place navigation drawers header below statusbar?

I want my header of my Navigation drawer to be below the statusbar. When searching for solutions, every result is about how to place it under the status bar. I have of course tried to "reverse" theese solutions to place the header below. But it hasn't worked and I'm testing it on a Samsung Galaxy S7 API 23
Right now it looks like this:
This is my layout containing DrawerLayout, NavigationView:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns: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"
android:background="#00ffff"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
android:id="#+id/toolbar_drawer_layout"
layout="#layout/navdrawer_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/arion_darkgray"
android:fitsSystemWindows="true"
app:headerLayout="#layout/navdrawer_header"
app:itemBackground="#drawable/nav_drawer_selector"
app:itemIconTint="#fff"
app:itemTextColor="#fff"
app:menu="#menu/navdrawer_menu"
app:theme="#style/custom_navDrawer_style" />
</android.support.v4.widget.DrawerLayout>
Toolbar layout:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MyHorseActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/myhorse_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/arion_darkblue">
<RelativeLayout
android:id="#+id/myhorse_toolbar_innerlayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#android:color/transparent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingRight="70dp"
android:text="My Horse"
android:textColor="#fff"
android:textSize="24sp" />
<ImageView
android:backgroundTint="#ff0000"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:background="#drawable/circle_shape" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<include
layout="#layout/divider_lightblue"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true">
</include>
</android.support.design.widget.AppBarLayout>
<include
android:id="#+id/activity"
layout="#layout/myhorse_activity_" />
Much of this is auto generated by Android Studio after I created my NavigationDrawer Class from the wizard
You have not put your xml fully so I don't know whats wrong with your xml but if you want your navigation drawer below action bar then put your drawerlayout below your toolbar as follows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--Start of the Toolbar and its items -->
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" />
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"></LinearLayout>
<!--Used for displaying Navigation Drawer slide-->
<LinearLayout
android:id="#+id/navigation_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical">
<FrameLayout
android:id="#+id/navigation_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
According to your edited question drawerlayout xml would be like
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/toolbar_drawer_layout"
layout="#layout/navdrawer_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns: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"
android:background="#00ffff"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
android:id="#+id/activity"
layout="#layout/myhorse_activity_" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/arion_darkgray"
android:fitsSystemWindows="true"
app:headerLayout="#layout/navdrawer_header"
app:itemBackground="#drawable/nav_drawer_selector"
app:itemIconTint="#fff"
app:itemTextColor="#fff"
app:menu="#menu/navdrawer_menu"
app:theme="#style/custom_navDrawer_style" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
and toolbar layout will be like
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MyHorseActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/myhorse_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/arion_darkblue">
<RelativeLayout
android:id="#+id/myhorse_toolbar_innerlayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#android:color/transparent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingRight="70dp"
android:text="My Horse"
android:textColor="#fff"
android:textSize="24sp" />
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:background="#drawable/circle_shape"
android:backgroundTint="#ff0000" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<include
layout="#layout/divider_lightblue"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
I used the xml file below to achieve what you asked. But this way, the drawer opens below both the "status bar" and the "toolbar"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include xmlns:android="http://schemas.android.com/apk/res/android" layout="#layout/toolbar" />
<android.support.v4.widget.DrawerLayout
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:elevation="5dp">
<FrameLayout
android:id = "#+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</FrameLayout>
<ListView
android:background="#ffffff"
android:id = "#+id/drawerList"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:elevation="5dp"></ListView>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>

android navigation view - clipped drawer

I follow the google drawer spec
And I use the default style "NavigationView" class in android-support-design library, the drawer will be the "full-height" style:
But actually I need the "clipped" drawer:
How to make the clipped drawer?
Any suggestion?
Thanks a lot!
edit: .xml file
<?xml version="1.0" encoding="utf-8"?>
<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_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" >
<!-- include your content layout -->
<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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/toolbar" />
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<fragment
android:id="#+id/homepage"
android:name="com.technotalkative.navigationviewdemo.MyFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
<!-- Navigation view -->
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/drawer_header"
android:layout_marginTop="#dimen/topMargin"
app:menu="#menu/drawer_view" />
</android.support.v4.widget.DrawerLayout>
I edited my code, may it works for you.
<?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_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
<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_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/drawer_header"
app:menu="#menu/drawer_view" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>

Categories

Resources