I check out all the question and also google a lot I just want to remove this padding between each item in navigation view. Help me to sort out this problem thanks in advance.
This is the code of my main_drawer
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single" android:id="#+id/home1"
>
<item
android:id="#+id/home"
android:title="Home"
/>
</group>
<group android:checkableBehavior="single" android:id="#+id/aboutus1">
<item
android:id="#+id/nav_camera"
android:title="AboutUs" />
</group>
<group android:checkableBehavior="single" android:id="#+id/Services1">
<item
android:id="#+id/nav_gallery"
android:title="Services" />
</group>
<group android:checkableBehavior="single" android:id="#+id/consultation1">
<item
android:id="#+id/nav_slideshow"
android:title="Consultation" />
</group>
<group android:checkableBehavior="single" android:id="#+id/gallery1">
<item
android:id="#+id/nav_manage"
android:title="Gallery" />
</group>
<group android:checkableBehavior="single" android:id="#+id/appoinment1">
<item
android:id="#+id/nav_manage1"
android:title="Appoinment" />
</group>
<group android:checkableBehavior="single" android:id="#+id/Contact_Us1">
<item
android:id="#+id/Contact_Us"
android:title="Contact Us" />
</group>
<item android:title="Communicate">
<menu>
<item
android:id="#+id/nav_share"
android:icon="#drawable/ic_menu_share"
android:title="Share" />
<item
android:id="#+id/nav_send"
android:icon="#drawable/ic_menu_send"
android:title="Send" />
</menu>
</item>
</menu>
My image is ...
According to source code of NavigationView found here, it led me to NavigationMenuPresenter (found here) which says, every normal type in menu list inflates R.layout.design_navigation_item. So if you preview it (here) you will notice what preference it uses.
<android.support.design.internal.NavigationMenuItemView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/listPreferredItemHeightSmall"
android:paddingLeft="?attr/listPreferredItemPaddingLeft"
android:paddingRight="?attr/listPreferredItemPaddingRight"
android:foreground="?attr/selectableItemBackground"
android:focusable="true"/>
So, the final step is to override the style attribute, i.e. layout_height which references to "?attr/listPreferredItemHeightSmall" (default 48dp).
Open your styles.xml and override it by i.e using custom value:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<!-- HERE-->
<item name="listPreferredItemHeightSmall">18dp</item>
</style>
Original:
Custom:
Add this line to your dimens.xml file and customize this DP as per your need i have solved my problem by this lines.
<dimen name="design_navigation_padding_top_default" tools:override="true">5dp</dimen>
<dimen name="design_navigation_separator_vertical_padding" tools:override="true">0dp</dimen>
<dimen name="design_navigation_padding_bottom" tools:override="true">5dp</dimen>
<dimen name="design_navigation_icon_size" tools:override="true">20dp</dimen>
<dimen name="design_navigation_icon_padding" tools:override="true">12dp</dimen>
Yes just add this parameter in your dimens.xml file
<dimen name="design_navigation_separator_vertical_padding" tools:override="true">0dp</dimen>
other possible values you can change are here https://github.com/android/platform_frameworks_support/blob/master/design/res/values/dimens.xml
OR
if you want to customize fully then you just need to add your own list view inside navigation drawer like this..
<?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">
<include
layout="#layout/app_bar_dashboard"
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"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/nav_header_dashboard"
android:id="#+id/header"/>
<ListView
android:id="#+id/lst_menu_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/white"
android:divider="#color/navigation_divider"
android:dividerHeight="1dp"
android:layout_marginTop="#dimen/padding10"/>
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
then provide your own custom padding to listview row
You can put all your item in one group then you don't need to remove the padding
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_camera"
android:icon="#drawable/ic_menu_camera"
android:title="Home" />
<item
android:id="#+id/nav_gallery"
android:icon="#drawable/ic_menu_gallery"
android:title="Camera" />
<item ...
...>
</group>
Related
I've started the default Android project, "Navigation Drawer Activity".
I've changed the theme to:
<!-- <style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.DarkActionBar">-->
<style name="Theme.MyApplication" parent="Theme.Material3.DayNight.NoActionBar">
I've added a group item:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_home"
android:icon="#drawable/ic_menu_camera"
android:title="#string/menu_home" />
<item
android:id="#+id/nav_gallery"
android:icon="#drawable/ic_menu_gallery"
android:title="#string/menu_gallery" />
<item
android:id="#+id/nav_slideshow"
android:icon="#drawable/ic_menu_slideshow"
android:title="#string/menu_slideshow" />
</group>
<!-- added this:-->
<group
android:id="#+id/nav_other"
android:checkableBehavior="single">
<item
android:id="#+id/nav_cancel_payment"
android:icon="#drawable/ic_menu_slideshow"
android:title="Test Title"
android:enabled="true"/>
</group>
</menu>
The horizontal line has padding left and right. I want 0 padding. How can I achieve this?
The padding of the divider (with M3) is defined by the attributes dividerInsetStart and dividerInsetEnd (default value with M3 = 28dp).
You can override them using in your layout:
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
app:dividerInsetStart="0dp"
app:dividerInsetEnd="0dp"
or with a custom style:
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
style="#style/App.Material3.NavigationView"
where:
<style name="App.Material3.NavigationView" parent="Widget.Material3.NavigationView">
<item name="dividerInsetStart">0dp</item>
<item name="dividerInsetEnd">0dp</item>
</style>
My MenuItem:
How to right align text of MenuItem in Toolbar, Icon in first next text, like this:
code of menu_setting.xml for MenuItem:
<?xml version="1.0" encoding="utf-8"?>
<menu
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"
tools:context=".MainActivity">
<item
android:title="Main Menu"
app:showAsAction="always"
android:icon="#drawable/ic_more_vert">
<menu>
<item
android:id="#+id/about_app"
android:orderInCategory="100"
android:title="About app"
android:icon="#drawable/ic_info"
app:showAsAction="never" />
<item
android:id="#+id/contact_us"
android:orderInCategory="100"
android:title="Contact us"
android:icon="#drawable/ic_email"
app:showAsAction="never" />
</menu>
</item>
</menu>
Thanks in advance :)
<?xml version="1.0" encoding="utf-8"?>
<menu 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"
tools:context=".activities.MainActivity">
<item
android:id="#+id/action_notification1"
android:icon="#android:drawable/btn_dropdown"
android:title="action_notification"
app:showAsAction="always">
<menu>
<item
android:id="#+id/profile"
android:icon="#android:drawable/ic_menu_edit"
android:orderInCategory="100"
android:title="PROFILE" />
<item
android:id="#+id/c"
android:icon="#android:drawable/ic_menu_edit"
android:orderInCategory="100"
android:title="COMPLETED TRIPS" />
</menu>
</item>
</menu>
You can use girdle for align text of MenuItem in Toolbar:
dependencies {
compile 'com.lucasurbas:guidelinescompattoolbar:1.0.0'
}
This is how it should look like:
Change your style.xml code like this:
<style name=”Theme.GuidelinesCompat.Light.DarkToolbar”
parent=”Theme.AppCompat.Light.DarkActionBar”>
...
<!— Toolbar styles -->
<item name=”toolbarStyle”>#style/Custom.Widget.Toolbar</item>
<item name=”toolbarNavigationButtonStyle”>
#style/Custom.Widget.Toolbar.Button.Navigation</item>
</style>
<style name=”Custom.Widget.Toolbar” parent=”Widget.AppCompat.Toolbar”>
<item name=”maxButtonHeight”>48dp</item>
<item name=”android:paddingLeft”>
#dimen/toolbar_horizontal_padding</item>
<item name=”android:paddingRight”>
#dimen/toolbar_horizontal_padding</item>
<item name=”contentInsetStart”>
#dimen/first_keyline</item>
</style>
<style name=”Custom.Widget.Toolbar.Button.Navigation”
parent=”Widget.AppCompat.Toolbar.Button.Navigation”>
<item name=”android:minWidth”>48dp</item>
</style>
Here are necessary resources:
<resources>
<dimen name=”first_keyline”>24dp</dimen>
<dimen name=”second_keyline”>80dp</dimen>
<dimen name=”toolbar_horizontal_padding”>12dp</dimen>
</resources>
layout/layout.xml
<android.support.v7.widget.Toolbar
android:id=”#+id/toolbar”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:minHeight=”?attr/actionBarSize”
android:elevation=”6dp”
android:background=”#color/colorPrimary”
app:navigationIcon=”#drawable/ic_menu_white_24dp”
app:contentInsetStart=”#dimen/second_keyline”
app:theme=”#style/Theme.GuidelinesCompat.DarkToolbar”
app:popupTheme=”#style/Toolbar.Popup.AppCompat” />
Try this it helps you.
You have to try like this
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/about"
android:title="About"
android:gravity="right" />
<item android:id="#+id/help"
android:title="Help"
android:gravity="right" />
</menu>
I have a problem I want to move the text next to the picture this is a picture of the problem
https://imgur.com/a/E2mKn
I want to get this
https://imgur.com/a/7wgkn
My menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layoutDirection="ltr">
<group>
<item
android:id="#+id/menu_login"
android:title="Login"
android:icon="#drawable/icon_login"
/>
<item
android:id="#+id/menu_myfile"
android:title=""
android:icon="#drawable/icon_login"
android:visible="false"
/>
<item
android:id="#+id/menu_favorites"
android:title="Favorites"
android:icon="#drawable/icon_favorites"/>
<item
android:id="#+id/menu_rate"
android:title="Rate us"
android:icon="#drawable/icon_rate"/>
<item
android:id="#+id/menu_logout"
android:title="Logout"
android:icon="#drawable/icon_logout"
android:visible="false"
/>
</group>
<group
android:id="#+id/group_two">
<item android:title="Subscribe to us">
<menu>
<item
android:id="#+id/menu_facebook"
android:title="Facebook"
android:icon="#drawable/icon_facebook"/>
<item
android:id="#+id/menu_telegram"
android:title="Telegram"
android:icon="#drawable/icon_telegram"/>
<item
android:id="#+id/menu_instagram"
android:title="Instagram"
android:icon="#drawable/icon_instagram"/>
<item
android:id="#+id/menu_twitter"
android:title="Twitter"
android:icon="#drawable/icon_twitter"/>
</menu>
</item>
</group>
</menu>
I try to use this but it's not working
android:layoutDirection="ltr"
The problem is only on some old devices, I wish to get help thanks a lot.
You have to try like this
<?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/cc_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
.
.
.
.
.
<android.support.design.widget.NavigationView
android:id="#+id/cc_nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/am_nav_header_main_new"
app:menu="#menu/am_main_navigation_items" />
</android.support.v4.widget.DrawerLayout>
am_main_navigation_items.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/cc_nav_home"
android:icon="#drawable/ic_dashboard_primary"
android:title="#string/nav_dashboard" />
<item
android:id="#+id/am_nav_auditList"
android:icon="#drawable/ic_audits_primary"
android:title="#string/nav_auditList" />
<item
android:id="#+id/nav_about"
android:icon="#drawable/ic_about_primary"
android:title="#string/cc_nav_about" />
<item
android:id="#+id/nav_app_info"
android:icon="#drawable/ic_info_outline_primary"
android:title="#string/cc_nav_app_info" />
</group>
<group
android:id="#+id/group_two">
<item android:title="Subscribe to us">
<menu>
<item
android:id="#+id/menu_facebook"
android:title="Facebook"
android:icon="#drawable/icon_facebook"/>
<item
android:id="#+id/menu_telegram"
android:title="Telegram"
android:icon="#drawable/icon_telegram"/>
<item
android:id="#+id/menu_instagram"
android:title="Instagram"
android:icon="#drawable/icon_instagram"/>
<item
android:id="#+id/menu_twitter"
android:title="Twitter"
android:icon="#drawable/icon_twitter"/>
</menu>
</item>
</group>
</menu>
This will help, layoutDirection was introduced in API 17, all devices below should call this line:
ViewCompat.setLayoutDirection( findViewById(R.id.my_view) , ViewCompat.LAYOUT_DIRECTION_LTR );
oh and make sure that for the above you will use android.support.v4.view.ViewCompat import
or you can just add this piece to the menu items:
android:layout_gravity="end"
Try placing the entire menu inside a FrameLayout. Then set the layout_width of the frame layout to wrap_content.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<menu>
<group>
<item
android:id="#+id/menu_login"
android:icon="#drawable/icon_login"
android:title="Login" />
<item
android:id="#+id/menu_myfile"
android:icon="#drawable/icon_login"
android:title=""
android:visible="false" />
<item
android:id="#+id/menu_favorites"
android:icon="#drawable/icon_favorites"
android:title="Favorites" />
<item
android:id="#+id/menu_rate"
android:icon="#drawable/icon_rate"
android:title="Rate us" />
<item
android:id="#+id/menu_logout"
android:icon="#drawable/icon_logout"
android:title="Logout"
android:visible="false" />
</group>
<group android:id="#+id/group_two">
<item android:title="Subscribe to us">
<menu>
<item
android:id="#+id/menu_facebook"
android:icon="#drawable/icon_facebook"
android:title="Facebook" />
<item
android:id="#+id/menu_telegram"
android:icon="#drawable/icon_telegram"
android:title="Telegram" />
<item
android:id="#+id/menu_instagram"
android:icon="#drawable/icon_instagram"
android:title="Instagram" />
<item
android:id="#+id/menu_twitter"
android:icon="#drawable/icon_twitter"
android:title="Twitter" />
</menu>
</item>
</group>
</menu>
</FrameLayout>
I check out all the question and also google a lot I just want to remove this padding between each item in navigation view. Help me to sort out this problem thanks in advance.
This is the code of my main_drawer
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single" android:id="#+id/home1"
>
<item
android:id="#+id/home"
android:title="Home"
/>
</group>
<group android:checkableBehavior="single" android:id="#+id/aboutus1">
<item
android:id="#+id/nav_camera"
android:title="AboutUs" />
</group>
<group android:checkableBehavior="single" android:id="#+id/Services1">
<item
android:id="#+id/nav_gallery"
android:title="Services" />
</group>
<group android:checkableBehavior="single" android:id="#+id/consultation1">
<item
android:id="#+id/nav_slideshow"
android:title="Consultation" />
</group>
<group android:checkableBehavior="single" android:id="#+id/gallery1">
<item
android:id="#+id/nav_manage"
android:title="Gallery" />
</group>
<group android:checkableBehavior="single" android:id="#+id/appoinment1">
<item
android:id="#+id/nav_manage1"
android:title="Appoinment" />
</group>
<group android:checkableBehavior="single" android:id="#+id/Contact_Us1">
<item
android:id="#+id/Contact_Us"
android:title="Contact Us" />
</group>
<item android:title="Communicate">
<menu>
<item
android:id="#+id/nav_share"
android:icon="#drawable/ic_menu_share"
android:title="Share" />
<item
android:id="#+id/nav_send"
android:icon="#drawable/ic_menu_send"
android:title="Send" />
</menu>
</item>
</menu>
My image is ...
According to source code of NavigationView found here, it led me to NavigationMenuPresenter (found here) which says, every normal type in menu list inflates R.layout.design_navigation_item. So if you preview it (here) you will notice what preference it uses.
<android.support.design.internal.NavigationMenuItemView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/listPreferredItemHeightSmall"
android:paddingLeft="?attr/listPreferredItemPaddingLeft"
android:paddingRight="?attr/listPreferredItemPaddingRight"
android:foreground="?attr/selectableItemBackground"
android:focusable="true"/>
So, the final step is to override the style attribute, i.e. layout_height which references to "?attr/listPreferredItemHeightSmall" (default 48dp).
Open your styles.xml and override it by i.e using custom value:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<!-- HERE-->
<item name="listPreferredItemHeightSmall">18dp</item>
</style>
Original:
Custom:
Add this line to your dimens.xml file and customize this DP as per your need i have solved my problem by this lines.
<dimen name="design_navigation_padding_top_default" tools:override="true">5dp</dimen>
<dimen name="design_navigation_separator_vertical_padding" tools:override="true">0dp</dimen>
<dimen name="design_navigation_padding_bottom" tools:override="true">5dp</dimen>
<dimen name="design_navigation_icon_size" tools:override="true">20dp</dimen>
<dimen name="design_navigation_icon_padding" tools:override="true">12dp</dimen>
Yes just add this parameter in your dimens.xml file
<dimen name="design_navigation_separator_vertical_padding" tools:override="true">0dp</dimen>
other possible values you can change are here https://github.com/android/platform_frameworks_support/blob/master/design/res/values/dimens.xml
OR
if you want to customize fully then you just need to add your own list view inside navigation drawer like this..
<?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">
<include
layout="#layout/app_bar_dashboard"
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"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/nav_header_dashboard"
android:id="#+id/header"/>
<ListView
android:id="#+id/lst_menu_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/white"
android:divider="#color/navigation_divider"
android:dividerHeight="1dp"
android:layout_marginTop="#dimen/padding10"/>
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
then provide your own custom padding to listview row
You can put all your item in one group then you don't need to remove the padding
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_camera"
android:icon="#drawable/ic_menu_camera"
android:title="Home" />
<item
android:id="#+id/nav_gallery"
android:icon="#drawable/ic_menu_gallery"
android:title="Camera" />
<item ...
...>
</group>
I am trying to figure out how I can change color of sub-menu items which is actually attached to navigation view. Following codes are actually from default template of Navigation Drawer which is available in android studio.
activity_main_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_camara"
android:icon="#android:drawable/ic_menu_camera"
android:title="Import"
/>
<item
android:id="#+id/nav_gallery"
android:icon="#android:drawable/ic_menu_gallery"
android:title="Gallery"/>
<item
android:id="#+id/nav_slideshow"
android:icon="#android:drawable/ic_menu_slideshow"
android:title="Slideshow"/>
<item
android:id="#+id/nav_manage"
android:icon="#android:drawable/ic_menu_manage"
android:title="Tools"/>
</group>
<item android:title="Communicate">
<menu>
<item
android:id="#+id/nav_share"
android:icon="#android:drawable/ic_menu_share"
android:title="Share"/>
<item
android:id="#+id/nav_send"
android:icon="#android:drawable/ic_menu_send"
android:title="Send"/>
</menu>
</item>
</menu>
activity_main.xml
<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"
android:background="#512DA8"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer"
app:itemTextColor="#drawable/nav_menu_item_color"
app:itemIconTint="#drawable/nav_menu_item_color"/>
</android.support.v4.widget.DrawerLayout>
and I have a drawable file for click and normal color which is actualy used above.
nav_menu_item_color.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<selector>
<item android:color="#color/navTextHover" android:state_checked="true" />
<item android:color="#color/navTextNormal" />
</selector>
So, you can see result image as I attached below :-
Colors not working for sub menu, so, what I want to do is .. I want to change color of menu item "communicate" and sub-menu item "send" and "share" as it is working for root menu items
Changing the color of the header and Subheader in the Navigation View and paste the below code in your res>values>styles.xml
<style name="NavigationViewStyle">
<item name="android:textSize">16sp</item> <!-- menu item text size-->
<item name="android:listPreferredItemHeightSmall">40dp</item><!-- menu item height-->
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#FFB300</item>
</style>
NavigationView set the header color as textcolor secondary and subheader color as the textColor Primary .
finally, add this style in the navigationView
<android.support.design.widget.NavigationView
android:id="#+id/navview"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#022F56"
app:headerLayout="#layout/sidebar_header"
app:theme="#style/NavigationViewStyle"
app:menu="#menu/sidebar_home"/>
And the output will be,
Thats all, happy Coding.
Your submenu needs to be wrapped in a menu & group tag like below. This will allow you to select one of any of the menu items at a time. You can select them by setting the item as checked in your NavigationView.OnNavigationItemSelectedListener.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav1"
android:checked="true"
android:icon="#drawable/myd1"
android:title="Nav 1"
/>
</group>
<item android:title="#string/nav_item_subheading_app">
<menu>
<group android:checkableBehavior="single">
<item
android:id="#+id/nav1"
android:icon="#drawable/myd1"
android:title="Nav 1"
/>
</group>
</menu>
</item>
</menu>