Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Background Color of Navigation Drawer

I wanted to set the background color of my Navigation drawer in java but it seems as setBackgroundColor and all similar methods have no effect. Only the XML line android:background="@color/mycolor" is working. If remove the xml line and try one of the methods the drawer just stays transparent.

Any ideas?

like image 517
mike.b93 Avatar asked Jun 13 '13 16:06

mike.b93


People also ask

How do I customize my navigation drawer?

Android App Development for BeginnersStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. Step 3 − Add the following code to res/layout/nav_header_main.


1 Answers

In your activity_main.xml include the following

<android.support.design.widget.NavigationView     android:id="@+id/navigation_view"     android:layout_width="wrap_content"     android:layout_height="match_parent"     android:layout_gravity="start"     app:headerLayout="@layout/navigation_drawer_header"     app:menu="@menu/menu_drawer"     android:background="@color/color_navigation_list_background"     app:itemIconTint="@color/color_selector_navigation_item"     app:itemTextColor="@color/color_selector_navigation_item"/> 
like image 95
Goodlife Avatar answered Sep 18 '22 20:09

Goodlife