How to change color of text and icon of Sub-Menu attached to Navigation view?

Vivek Kumar

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 :-Color of Sub-Menu Items didn't change

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

fractalwrench

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>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to change the color of the hamburger icon in the navigation view in android studio

From Dev

Change menu navigation icon color in xml for Android

From Dev

Change menu navigation icon color in xml for Android

From Dev

how to change size of navigation view menu items and text?? How to change space between menu?

From Dev

Change the color of menu icon

From Dev

How to change the color of menu text?

From Dev

how to change the icon color of search view

From Dev

Navigation Drawer change the Icon and text color of highlighted item

From Dev

How to change the color of navigation bar on a specific view

From Dev

how to change background color of the navigation bar and navigation text color

From Dev

how to change the text color of navigation bar

From Dev

How to change Toolbar navigation icon and options menu margin

From Dev

How to change icon at Navigation menu Bar at Andorid Studio?

From Dev

How to change text color on OnMouseHover in a Dropdown Menu

From Dev

How to change the text color of context menu item

From Java

How to change color of hamburger icon in material design navigation drawer

From Dev

How to change Navigation drawer launcher icon color in Android

From Dev

Change color of default navigation menu

From Dev

How to change text color of a custom view list item for menu drawer when selected - DrawerLayout

From Dev

How to change text color of a custom view list item for menu drawer when selected - DrawerLayout

From Dev

Android Navigation drawer menu item icon color

From Dev

How to change the color of the text inside a View?

From Dev

How to add sub menu to Navigation menu

From Dev

How to have a text view in my navigation drawer after menu items?

From Dev

Change the color of Navigation Drawer indicator icon

From Dev

Cannot change navigation drawer icon color android

From Dev

Change Navigation Drawer text color

From Dev

How to change inactive icon/text color on tab bar?

From Java

How can I change an icon and text's color on hover?

Related Related

  1. 1

    how to change the color of the hamburger icon in the navigation view in android studio

  2. 2

    Change menu navigation icon color in xml for Android

  3. 3

    Change menu navigation icon color in xml for Android

  4. 4

    how to change size of navigation view menu items and text?? How to change space between menu?

  5. 5

    Change the color of menu icon

  6. 6

    How to change the color of menu text?

  7. 7

    how to change the icon color of search view

  8. 8

    Navigation Drawer change the Icon and text color of highlighted item

  9. 9

    How to change the color of navigation bar on a specific view

  10. 10

    how to change background color of the navigation bar and navigation text color

  11. 11

    how to change the text color of navigation bar

  12. 12

    How to change Toolbar navigation icon and options menu margin

  13. 13

    How to change icon at Navigation menu Bar at Andorid Studio?

  14. 14

    How to change text color on OnMouseHover in a Dropdown Menu

  15. 15

    How to change the text color of context menu item

  16. 16

    How to change color of hamburger icon in material design navigation drawer

  17. 17

    How to change Navigation drawer launcher icon color in Android

  18. 18

    Change color of default navigation menu

  19. 19

    How to change text color of a custom view list item for menu drawer when selected - DrawerLayout

  20. 20

    How to change text color of a custom view list item for menu drawer when selected - DrawerLayout

  21. 21

    Android Navigation drawer menu item icon color

  22. 22

    How to change the color of the text inside a View?

  23. 23

    How to add sub menu to Navigation menu

  24. 24

    How to have a text view in my navigation drawer after menu items?

  25. 25

    Change the color of Navigation Drawer indicator icon

  26. 26

    Cannot change navigation drawer icon color android

  27. 27

    Change Navigation Drawer text color

  28. 28

    How to change inactive icon/text color on tab bar?

  29. 29

    How can I change an icon and text's color on hover?

HotTag

Archive