Set Background Color of Navigation Drawer

泄露秘密 提交于 2019-12-03 01:03:11

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"/>
mike.b93

I just solved my own problem.

I totally forgot that it's not the DrawerLayout I want to set the background to, but the ListView inside.

I admit I made it somewhat hard for you guys without adding code to my post -.-'

So instead of:

private DrawerLayout mDrawerLayout;
(...)
mDrawerLayout.setBackgroundResource(int);

I had to do this:

private ListView mDrawerList;
(...)
mDrawerList.setBackgroundResource(int);

cast your navigation drawer to navigationView and do as follows

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