0

I'm developing an Android application, I have to customize a navigation drawer, this is the code that i use :

<?xml version="1.0" encoding="utf-8"?>
<menu
 xmlns:android="http://schemas.android.com/apk/res/android">    
  <item
   android:title="Discover">      <--- LABEL
   <menu>
    <item
     android:id="@+id/nav_qrcode"         <--- Item of menu
     android:icon="@drawable/read_qr"
     android:title="Read QRCode" />

    <item
     android:id="@+id/nav_favorite"          <--- Item of menu
     android:icon="@drawable/favorite"
     android:title="Favorite" />
   </menu>
 </item>
</menu>

This is he drawer layout:

<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"
    android:background="@color/gold"
    app:itemTextColor="@color/white"
    app:menu="@menu/main_drawer" />
</android.support.v4.widget.DrawerLayout>

This is the java code:

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.setItemIconTintList(null);

I have to customize the navigation drawer, the background of the label must be "gold" the item "white".

How i can do this ?

Elisa
  • 5
  • 2

1 Answers1

0

First method, you can follow this topic: How to change the Text color of Menu item in Android?

Secondly, you can use a listview + custom adapter and then add this listview to DrawerLayout instead of defining in XML like that.

Community
  • 1
  • 1
xxx
  • 3,315
  • 5
  • 21
  • 40