How to remove NavigationView item background - android

This seems like it should be trivial with the itemBackground attribute, but for some reason, it isn't working.
As shown below, I can successfully add my own background (in blue), but the original ripple (grey rectangle) is still visible.
Setting itemBackground to null doesn't seem to do the trick either.
My navigation view:
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
style="#style/Widget.MaterialComponents.NavigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:itemBackground="#drawable/nav_item_background"
app:menu="#menu/main_drawer" />
(Basically untouched style wise from the generated view)
My ripple:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/accent_ripple">
<item
android:id="#android:id/mask"
android:right="8dp">
<shape android:shape="rectangle">
<corners
android:bottomRightRadius="50dp"
android:topRightRadius="50dp" />
<solid android:color="#fff" />
</shape>
</item>
</ripple>
My app theme also extends Theme.MaterialComponents, so I'm out of ideas.

If you want a custom shape in your Item Background don't use the app:itemBackground attribute.
Use the app:itemShapeAppearanceOverlay and the app:itemShapeFillColor attributes:
<com.google.android.material.navigation.NavigationView
app:itemShapeAppearanceOverlay="#style/ShapeAppearanceOverlay.Item"
app:itemShapeFillColor="#color/nav_item_shape_fill"
android:theme="#style/ThemeOverlay.NavigationView"
../>
where:
<style name="ShapeAppearanceOverlay.Item" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSizeTopRight">16dp</item>
<item name="cornerSizeBottomRight">16dp</item>
<item name="cornerSizeBottomLeft">0dp</item>
<item name="cornerSizeTopLeft">0dp</item>
</style>
and the color selector is something like:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="0.12" android:color="?attr/colorPrimary" android:state_activated="true"/>
<item android:alpha="0.12" android:color="?attr/colorPrimary" android:state_checked="true"/>
<item android:color="#android:color/transparent"/>
</selector>
Currently there isn't a method to remove the ripple outside the shape in the item.
However you can use the android:theme to override the color used by the ripple.
<style name="ThemeOverlay.NavItem.Ripple" parent="">
<item name="android:colorControlHighlight">#android:color/transparent</item>
</style>
Check this issue for updates.

just you can do like this :
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigationView"
android:layout_width="230dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/colorPrimaryDark">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/layout_navigation_header" />
<include layout="#layout/layout_navigation" />
</LinearLayout>
</com.google.android.material.navigation.NavigationView>

Why don't you override it with your own drawable? You can use your own color and effect or even make the ripple effect transparent with hex
#ffffffff
or
#android:color/transparent

Related

Applying a gradient background on a toolbar

I have created a custom gradient drawable file that i want to use as my Toolbar's background but i can't seem to apply it. It just shows up as plain gray (see the image). Am i doing something wrong? I looked at multiple posts but nothing has worked for me so far.
activity_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"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<Toolbar
android:id="#+id/home_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/home_toolbar_gradient"
android:elevation="4dp"
android:minHeight="70dp"
android:theme="#style/customToolbar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<TextView
android:id="#+id/title_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/Montserrat-Bold"
android:gravity="center"
android:text="#string/home"
android:textAlignment="center"
android:textColor="#android:color/white" />
</Toolbar>
<!-- Using a view with a gradient to create a drop navbar_shadow effect for the navbar -->
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_above="#id/bottom_nav_bar"
android:background="#drawable/navbar_shadow" />
<com.google.android.material.bottomnavigation.BottomNavigationView
app:labelVisibilityMode="labeled"
android:id="#+id/bottom_nav_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#android:color/white"
app:itemIconTint="#drawable/nav_selected_item_color"
app:itemTextColor="#drawable/nav_selected_item_color"
app:menu="#menu/bottom_nav_bar">
</com.google.android.material.bottomnavigation.BottomNavigationView>
</RelativeLayout>
home_toolbar_gradient.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:type="linear"
android:startColor="#color/toolbar_starting_color"
android:endColor="#color/toolbar_ending_color"
android:angle="75" />
</shape>
styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:fontFamily">#font/montserrat_medium</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<!-- Custom Rounded Dialog style -->
<style name="RoundedDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowBackground">#drawable/rounded_corners</item>
</style>
<style name="customToolbar" parent="Theme.AppCompat.Light.NoActionBar" />
</resources>
in MainActivity.java:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar homeToolbar = findViewById(R.id.home_toolbar);
setSupportActionBar(homeToolbar);
and in the manifest:
android:theme="#style/Theme.AppCompat.Light.DarkActionBar"
Try doing it dynamically:
setSupportActionBar(homeToolbar);
ActionBar actionbar = getSupportActionBar();
actionbar.setBackgroundDrawable(getResources().getDrawable(R.drawable.home_toolbar_gradient));
Read this. It says- Angle of the gradient, used only with linear gradient. Must be a multiple of 45 in the range [0, 315].
So, Change home_toolbar_gradient.xml drawable to
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:type="linear"
android:startColor="#FF33"
android:endColor="#AFF"
android:angle="45" />
</shape>
Try this:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient
android:angle="90"
android:centerColor="#555994"
android:endColor="#b5b6d2"
android:startColor="#555994"
android:type="linear" />
<corners
android:radius="0dp"/>
</shape>
For anyone interested, i actually found the issue. The angle attribute in a gradient drawable needs to be a multiple of 45 otherwise you'll get a subtle rendering error in the layout preview. Just change it to a multiple of it that suits your needs and the gradient will take effect.

ButtomNavigationView doesn't show ripple effect in Items Background

UPDATE:
The other question uses a white background and since it uses white background there is no ripple on the BottomNavigationBar (because the ripple itself is white). But in my case the ButtomNavigationBar is blue, and it reflects the ripple. In fact all of the colors except the white(that the other question uses) reflect the incomplete ripple.
ORIGINAL:
I am using ButtomNavigationView, and the problem is that it doesn't show ripple effect in the background of it's Items.
Or it doesn't care about app:itemBackground it just uses android:background value without any ripple effect.
I've tried using a ripple instead of selector in drawable-21 and changing the app:itemBackground color values but it is not working.
ButtomNavigationView:
<android.support.design.widget.BottomNavigationView
android:id="#+id/nav_view"
android:layout_width="0dp"
android:layout_height="56dp"
android:theme="#style/BottomNavigationStyle"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/bottom_nav_menu" />
ButtomNavigationStyle:
<style name="BottomNavigationStyle">
<item name="itemBackground">#drawable/navigation_bar_item_bg</item>
<item name="itemIconTint">?attr/bottom_nav_colors</item>
<item name="itemTextColor">?attr/bottom_nav_colors</item>
<item name="android:background">?attr/colorPrimary</item>
<item name="android:fontFamily">#font/iransans_mobile</item>
</style>
bottom_nav_menu:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/navigation_mylibrary"
android:icon="#drawable/ic_library_books_black_24dp"
android:title="#string/title_mylibrary" />
<item
android:id="#+id/navigation_search"
android:icon="#drawable/ic_search_black_24dp"
android:title="#string/title_search" />
.
.
.
</menu>
navigation_bar_item_bg:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/black_color"
android:state_checked="true"/>
<item android:drawable="#drawable/black_color"/>
</selector>
ScreenShot:
https://firebasestorage.googleapis.com/v0/b/library-1696f.appspot.com/o/Screenshot%20from%202019-06-17%2005-39-23.png?alt=media&token=20efbe56-3234-47ab-b6cc-898124b77762
I've searched and I've found that it is a library bug that is not fixed yet.
But I've found a solution for this.
1) Since the android:background and android:itemBackground don't work correctly delete both of them from BottomNavigationView.
2) Create a new FrameLayout and put your BottomNavigationView inside FrameLayout.
3) change these properties of the FrameLayout:
android:layout_width="match_parent"
android:layout_height="wrap_content"
4)Finally Add your desired color for ButtomNavigationView into FrameLayout as android:background.
Example:
<FrameLayout
android:id="#+id/buttomnavigation_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/blue"><!--Background color for BNV-->
<android.support.design.widget.BottomNavigationView
android:id="#+id/nav_view"
android:layout_width="match_parent"
android:layout_height="56dp"
app:itemIconTint="#color/bottom_navigation_colors"
app:itemTextColor="#color/bottom_navigation_colors"
app:labelVisibilityMode="labeled"
app:menu="#menu/bottom_nav_menu"/>
</FrameLayout>
bottom_navigation_colors.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_checked="true"
android:color="#FFFFFF" />
<item
android:state_checked="false"
android:color="#C7FFFFFF" />
</selector>

Set Margin to Navigation Drawer's Default Divider

I tried to set margin to default navigation drawer's "divider" attribute. I found many approach in Stackoverflow form but none of the answers are adequate.
I could create a custom navigation drawer list without using /menu/activity_main_drawer.xml. That looks like what I want. But I have concerns about the performance of the application.
I want to add margin to default divider. Is there a way to customize default navigation drawer divider?
That is my customized divider. Everything is perfect.
That is the default navigation drawer's divider which I could not give any margin.
style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:listDivider">#color/colorAccent</item>
...
</style>
divider_layout.xml
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="60dp"
android:insetRight="8dp" >
<shape>
<solid android:color="#c0c0c0" />
</shape>
</inset>
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_camera"
android:icon="#drawable/rakipicon"
android:title="Import" />
<item
android:id="#+id/nav_gallery"
android:icon="#drawable/ic_menu_gallery"
android:title="Gallery" />
<item
android:id="#+id/nav_slideshow"
android:icon="#drawable/ic_menu_slideshow"
android:title="Slideshow" />
<item
android:id="#+id/nav_manage"
android:icon="#drawable/ic_menu_manage"
android:title="Tools" />
</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>
activity_main.xml
<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_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:divider="#drawable/divider_layout"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
I know it's been a while, but for anyone that might stumble upon this, I had the same issue and resolved it like this.
Where you define the navigation view, you can just set padding horizontal, which will set a padding for the entire navigation view. This will apply to the dividers as well.
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingHorizontal="24dp">
You can create a drawable named menu_divider.xml in your resources folder:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#c0c0c0"
android:left="16dp"
android:right="16dp" />
and set your navigation view to use it:
<style name="ThemeOverlay.App.NavigationView" parent="">
<item name="android:listDivider">#drawable/menu_divider</item>
</style>
Just add this in the drawer layout:
app:dividerInsetEnd="25dp"
app:dividerInsetStart="57dp"
Like below:
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:dividerInsetEnd="25dp"
app:dividerInsetStart="57dp"
app:elevation="32dp"
app:headerLayout="#layout/nav_header_main"
app:itemIconTint="#color/gray"
app:itemTextColor="#color/gray"
app:menu="#menu/activity_main_drawer">

How to change inactive color on bottom navigation?

I can't change inactive color on my bottom navigation
and this my xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/home_item"
android:icon="#drawable/ic_home"
android:color="#FFFFFF"
android:tint="#FFFFFF"
android:backgroundTint="#FFFFFF"
android:title="Home"
/>
<item
android:id="#+id/setting_item"
android:icon="#drawable/ic_setting"
android:color="#FFFFFF"
android:tint="#FFFFFF"
android:backgroundTint="#FFFFFF"
android:title="Setting"
/>
and this my java
bottomBar.getBar().setBackgroundColor(getResources().getColor(R.color.bottom_tabs));
bottomBar.setActiveTabColor("#FFFFFE");
anyone can help?
If you are using the BottomNavigationView, the solution could be easy.
You just need to create a selector as a ColorStateList, then assign the selector to the "itemIconTint" attribute of the BottomNavigationView.
For example:
Create file inside drawable
bottom_nav_icon_color_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#android:color/white" />
<item android:state_pressed="true" android:state_enabled="true" android:color="#android:color/white" />
<item android:color="#color/InactiveBottomNavIconColor" />
</selector>
BotttomNavigationview.xml
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottomNavMainMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/BottomNavBarColor"
app:itemIconTint="#drawable/bottom_nav_icon_color_selector"
app:itemTextColor="#drawable/bottom_nav_icon_color_selector"
app:menu="#menu/bottom_navigation_menu" />
Chrislis answer is a good start. However I like to solve this problem via styling and theming. I also used the new material BottomNavigationView for this example.
Create a new file under the color folder, for example: bottom_nav_item_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/item_color_active" android:state_checked="true"/>
<item android:color="#color/item_color_inactive"/>
</selector>
Add this line to your base theme located in themes.xml
<item name="bottomNavigationStyle">#style/BottomNavigationViewStyle</item>
Add this code to styles.xml
<style name="BottomNavigationViewStyle" parent="Widget.MaterialComponents.BottomNavigationView.Colored">
<item name="android:background">#color/my_background_color</item>
<item name="itemTextColor">#color/bottom_nav_item_color</item>
<item name="itemIconTint">#color/bottom_nav_item_color</item>
</style>
Now the BottomNavigationView should be styled correctly
Example layout file
<com.google.android.material.bottomnavigation.BottomNavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schema.android.com/apk/res/res-auto"
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="start"
app:menu="#menu/my_navigation_items" />
I've sligthly edited #Wirling answer to match Android Studio 4.2 Canary 16.
You just have to define your active/inactive colors under the color folder, for example bottom_nav_item.color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/item_color_active" android:state_checked="true"/>
<item android:color="#color/item_color_inactive"/>
</selector>
Then, in your BottomNavigationView just use previous created selector like this
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:itemIconTint="#color/bottom_nav_item_color"
app:itemTextColor="#color/bottom_nav_item_color"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/bottom_nav_menu" />
So its super simple. You have to create your selector in new .xml file and then use it for your BottomNavigationView in
app:itemIconTint="#color/bottom_nav_item_color"
app:itemTextColor="#color/bottom_nav_item_color"
Bottom Navigation select text and icon Color
first bottom navigation home layout activity
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorAccent"
android:theme="#style/ThemeOverlay.BottomNavView"
app:itemIconTint="#drawable/icon_color_selector"
app:itemTextColor="#drawable/selector"
app:labelVisibilityMode="labeled"
app:menu="#menu/home_menu">
</com.google.android.material.bottomnavigation.BottomNavigationView>
then selector file create in drawable
item_color_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/bottomBarItemColor" android:state_selected="true" />
<item android:color="#color/colorDivider" android:state_selected="false" />
then create text selected color xml file in drawable
text_color_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/white" android:state_selected="true" />
<item android:color="#color/colorDivider" android:state_selected="false" />
then add style on theme xml
<style name="ThemeOverlay.BottomNavView" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/colorWhite</item>
<item name="colorOnSurface">#color/colorDivider</item>
<item name="android:textColorSecondary">#color/colorDivider</item>
</style>
then create home menu xml file in res directory
home_menu.xml add in menu directory
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/nav_live_date"
android:icon="#drawable/icon_selector"
android:title="Live Data"
android:enabled="true"/>
<item
android:id="#+id/nav_house_details"
android:icon="#drawable/icon_selector"
android:title="House Details"
android:enabled="true"/>
<item
android:id="#+id/nav_attendance"
android:icon="#drawable/icon_selector"
android:title="Attendance"
android:enabled="true"/>
<item
android:id="#+id/nav_emp_details"
android:icon="#drawable/icon_selector"
android:title="Emp Details"
android:enabled="true"/>
End Thank you so much
<!-- Base application theme. -->
<style name="Theme.RunnerApp"
parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/white</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?
attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
In most of the case...developer change there theme to NoActionBar
But instead of
Theme.MaterialComponents.DayNight.NoActionBar
They change it into
Theme.AppCompat.DayNight.NoActionBar
That causes all these colour issues
Navigation component use material design so keep this point in mind
Try below code. Hope its helpful!!!
mBottomBar = BottomBar.attach(this, savedInstanceState);
mBottomBar.setItems(R.menu.bottombar_menu);
mBottomBar.getBar().setBackgroundResource(R.color.navigationColor);
mBottomBar.setOnMenuTabClickListener(new OnMenuTabClickListener() {

How to change the background color of a Navigation View sub menu header title?

Given a NavigationView with a section with sub menu items like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Sub items">
<menu>
<item android:title="Sub item 1" />
<item android:title="Sub item 2" />
</menu>
</item>
</menu>
Question: How do I change the background color of the Sub items row?
In my experiments, it looks like the color used for the sub menu header row/item is the same as the background color of the NavigationView (android:backgroundTint and android:background) but I have not found a way to specify the two separately. I need the background color to be one color and the sub menu header row/item another color.
itemBackground, itemIconTint and itemTextColor are simple xml-attributes that can be set, though you have to use a custom prefix instead of the android: one.
Example
<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">
<!-- Other layout views -->
<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:itemBackground="#drawable/my_ripple"
app:itemIconTint="#2196f3"
app:itemTextColor="#009688"
app:headerLayout="#layout/nav_header"
app:menu="#menu/drawer_view" />
</android.support.v4.widget.DrawerLayout>
Example
Create a new *.xml file in /res/color - let's name it state_list.xml - with the following content:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is used when the Navigation Item is checked -->
<item android:color="#009688" android:state_checked="true" />
<!-- This is the default text color -->
<item android:color="#E91E63" />
</selector>
and the simply reference it like this: app:itemTextColor="#color/state_list"
The same goes for itemIconTint. itemBackground expects a resource id.
use compile 'com.android.support:appcompat-v7:23.1.1'
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header_main_navigation"
app:itemBackground="#drawable/nav_view_item_background"
app:itemTextColor="#color/nav_item_text_color"
app:menu="#menu/activity_main_navigation_drawer" />
uses to the following XML file for item backgroud: nav_view_item_background.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/colorPrimary" android:state_checked="true" />
<item android:drawable="#android:color/transparent" />
uses to the following XML file for Text Color: nav_item_text_color
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/white" android:state_checked="true" />
<item android:color="#android:color/black" />

Categories

Resources