He's using the NavigationView with the support library android.support.design.widget. It works very well but I can not adjust the height and the margins, then it remains empty space between the toolbar and the first line. To understand the problem see the image. This is my XML. Thanks for your help.
<LinearLayout
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="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<include
android:id="#+id/toolbar_actionbar"
layout="#layout/toolbar_default"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
app:menu="#menu/main"/>
<!-- app:headerLayout="#layout/header" -->
</android.support.v4.widget.DrawerLayout>
toolbar_default
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
style="#style/ToolBarStyle"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="#dimen/abc_action_bar_default_height_material"
/>
Try adding this to your dimens.xml,
<dimen name="design_navigation_separator_vertical_padding">0dp</dimen>
Related
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.
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>
I know this has been asked before a lot of times, but I’m still not able to get it working. The app:layout_scrollFlags="scroll|enterAlways" parameter exists, but I think it’s got something to do with the nesting. My XML file below:
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:background="#color/colorBG"
android:fitsSystemWindows="true"
android:id="#+id/mDrawerLayout"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:context=".MainActivity">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/coordinatorLayout"
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout
android:fitsSystemWindows="true"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<!-- App Bar-->
<android.support.v7.widget.Toolbar
android:background="#color/colorPrimary"
android:id="#+id/mToolbar"
android:layout_height="50dp"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:theme="#style/AppTheme.Toolbar"
app:layout_scrollFlags="scroll|enterAlways"/>
<FrameLayout
android:id="#+id/containerView"
android:layout_height="match_parent"
android:layout_width="match_parent">
</FrameLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:background="#color/colorPrimaryLight"
android:id="#+id/mNavigationView"
android:layout_gravity="start"
android:layout_height="match_parent"
android:layout_width="wrap_content"
app:headerLayout="#layout/header"
app:itemBackground="#color/colorPrimaryLight"
app:itemIconTint="#color/colorText"
app:itemTextColor="#color/colorText"
app:menu="#menu/drawer"/>
</android.support.v4.widget.DrawerLayout>
Remove LinearLayout and add android.support.design.widget.AppBarLayout as a container of ToolBar.
Keep FrameLayout outside of android.support.design.widget.AppBarLayout.
Add app:layout_behavior="#string/appbar_scrolling_view_behavior" to FrameLayout
Update your activity_main.xml as below:
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:background="#color/colorBG"
android:fitsSystemWindows="true"
android:id="#+id/mDrawerLayout"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:context=".MainActivity">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/coordinatorLayout"
android:layout_height="match_parent"
android:layout_width="match_parent">
<!-- App Bar-->
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<!-- ToolBar-->
<android.support.v7.widget.Toolbar
android:background="#color/colorPrimary"
android:id="#+id/mToolbar"
android:layout_height="50dp"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:theme="#style/AppTheme.Toolbar"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
<!-- Content-->
<FrameLayout
android:id="#+id/containerView"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:background="#color/colorPrimaryLight"
android:id="#+id/mNavigationView"
android:layout_gravity="start"
android:layout_height="match_parent"
android:layout_width="wrap_content"
app:headerLayout="#layout/header"
app:itemBackground="#color/colorPrimaryLight"
app:itemIconTint="#color/colorText"
app:itemTextColor="#color/colorText"
app:menu="#menu/drawer"/>
</android.support.v4.widget.DrawerLayout>
Hope this will help!
My AppBar is doing weird things.
This is what it looks like on a 720x1280 screen:
It is how it's supposed to look like. And this is how it looks like on a 1080x1920 screen:
I was playing around with the toolbar height in the app_bar_main.xml, but I didn't like it, so I set it back to the default ?attr/actionBarSize value. What could be the problem? Here is my app_bar_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.koostamas.justtry.MainActivity">
<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="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
And here is my activity_main.xml:
<?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/app_bar"
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/containerView">
</FrameLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/drawerPane"
android:layout_gravity="start">
<!-- List of Actions (pages) -->
<ListView
android:id="#+id/navList"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:background="#color/busblue"/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
try update your code. As of me this issue is with your views.Your approach is not correct to add this. If you are including the Toolbar only then whats the need of coordinateLayout and AppBarLayout!
update app_bar_main.xml ocde with this
<?xml version="1.0" encoding="utf-8"?>
<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" />
update your activity_main.xml code with this
<?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">
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/app_bar"
layout="#layout/app_bar_main" />
<FrameLayout
android:id="#+id/containerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"></FrameLayout>
<RelativeLayout
android:id="#+id/drawerPane"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">
<!-- List of Actions (pages) -->
<ListView
android:id="#+id/navList"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#color/busblue"
android:choiceMode="singleChoice" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
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>