Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Change Navigation View Menu Background

In my app i want to change the navigation view menu background, but i dont know how to do this. All posts i have watched explains how to change each menu item background, but all i need is to change the entire background of the menu.

This is what i want to change, the entire white background:

enter image description here

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>

Is there anyway to change the white background from the activity_main_drawer layout?

activity_main.xml:

 <?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_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"
    app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" />

 </android.support.v4.widget.DrawerLayout>

Thanks in advance.

like image 693
user3065901 Avatar asked Oct 15 '15 09:10

user3065901


People also ask

How to change color of navigation View in android?

You can set background to your NavigationView to change its color like below (set to app_white ) & for header set any color as a background of drawer_header_layout. Show activity on this post. just add android:background="@color/yourColor" to the <android. support.

How to design navigation drawer in android studio?

The drawer icon is displayed on all top-level destinations that use a DrawerLayout . To add a navigation drawer, first declare a DrawerLayout as the root view. Inside the DrawerLayout , add a layout for the main UI content and another view that contains the contents of the navigation drawer.


2 Answers

You can set background to your NavigationView to change its color like below (set to app_white ) & for header set any color as a background of drawer_header_layout.

<android.support.design.widget.NavigationView
        android:id="@+id/adcl_navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/app_white"
        app:headerLayout="@layout/drawer_header_layout"
        app:itemIconTint="@color/app_secondary_text"
        app:itemTextColor="@color/app_secondary_text"
        app:menu="@menu/menu_drawer"
        app:theme="@style/ThemeOverlay.AppCompat.Light" />
like image 199
Ankii Rawat Avatar answered Oct 13 '22 22:10

Ankii Rawat


just add android:background="@color/yourColor" to the <android.support.design.widget.NavigationView.

like image 35
Daniel Santos Avatar answered Oct 14 '22 00:10

Daniel Santos