Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to style Menu Items in Navigation Drawer in Android?

I want to add style the Menu Items inside Navigation Drawer but I am unable to do so. I have looked up for some answers but couldn't done it.

enter image description here

Can anyone help, I would be grateful.

I am using the following theme Theme.AppCompat.Light.DarkActionBar

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group android:id="@+id/group1" android:checkableBehavior="single">
        <item android:title="Book Now!">
            <menu>
                <item android:title="item 1"
                    android:id="@+id/item1"
                    android:icon="@drawable/ic_menu_gallery"/>
                <item android:title="item 2"
                    android:id="@+id/item2"
                    android:icon="@drawable/ic_menu_gallery"/>
                <item android:title="item 3"
                    android:id="@+id/item3"
                    android:icon="@drawable/ic_menu_gallery"/>
                <item android:title="item 4"
                    android:id="@+id/item4"
                    android:icon="@drawable/ic_menu_gallery"/>
                <item android:title="item 5"
                    android:id="@+id/item5"
                    android:icon="@drawable/ic_menu_gallery"/>
            </menu>
        </item>
    </group>

</menu>
like image 804
Sikandar Ali Chishty Avatar asked Jul 04 '16 13:07

Sikandar Ali Chishty


People also ask

Which method is used to handle clicks on the menu items of the navigation view?

You have to use OnNavigationItemSelectedListener(MenuItem item) method.

What is a drawer menu?

The navigation drawer is a UI panel that shows your app's main navigation menu. The drawer appears when the user touches the drawer icon in the app bar or when the user swipes a finger from the left edge of the screen.


1 Answers

Step 1: Create Selector for change font color

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/red" android:state_checked="true" />
    <item android:color="#bdbdbd" />
</selector>

Step 2: Apply selector to navigation view by app:itemTextColor property

 <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/appColor"
        android:fitsSystemWindows="true"                               
        app:itemTextAppearance="@style/NavigationDrawerStyle"
        app:headerLayout="@layout/nav_header_home"
        app:itemBackground="@color/appColor"
        app:itemTextColor="@color/drawable_selector_drawer_item"
        app:menu="@menu/activity_home_drawer" />
like image 52
Vishal Patoliya ツ Avatar answered Sep 27 '22 22:09

Vishal Patoliya ツ