How to style Menu Items in Navigation Drawer in Android?

微笑、不失礼 提交于 2019-12-18 13:07:55

问题


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.

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>

回答1:


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" />



回答2:


Try to use new Android Design pattern navigation drawer which is very smooth and easy to manage. Check below link :

http://www.android4devs.com/2014/12/how-to-make-material-design-navigation-drawer.html



来源:https://stackoverflow.com/questions/38185891/how-to-style-menu-items-in-navigation-drawer-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!