I am devleoping an app in which i am using navigation drawer,in that when i am trying to put icon for items it is giving me the path fof the image like this: " res/drawale/bg.jpg". I am not getting how to do that.
Below is my code for main activity:
private void init_navigator() {
// Navigation Drawer
mTitle = mDrawerTitle = getTitle();
mDrawerLayout = (DrawerLayout) findViewById(R.id.main_activity_DrawerLayout);
mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.primaryDark));
mScrimInsetsFrameLayout = (ScrimInsetsFrameLayout) findViewById(R.id.main_activity_navigation_drawer_rootLayout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerItmes = getResources().getStringArray(R.array.drawer_titles);
mDrawerItmes = getResources().getStringArray(R.array.nav_drawer_icons);
Here is my code for string.xml
<string-array name="drawer_titles">
<item>About Us</item>
<item>FeedBack</item>
<item>Setting</item>
<item>Share App</item>
<item>Rate Us</item>
<item>Logout</item>
</string-array>
<array name="nav_drawer_icons">
<item>@drawable/bg</item>
<item>@drawable/bg</item>
<item>@drawable/bg</item>
<item>@drawable/bg</item>
<item>@drawable/b</item>
<item>@drawable/bg</item>
</array>
In your navigationview in xml add this:
app:menu="@menu/drawer_menu_icons"
Then create a new xml called drawer_menu_icons in menu folder and do this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group
android:id="@+id/homegroup"
android:checkableBehavior="single">
<item
android:id="@+id/nav_home"
android:icon="@drawable/homeicon"
android:title="Main screen" />
<item
android:id="@+id/nav_branches"
android:icon="@drawable/backspace"
android:title="Branch selection" />
</group>
</menu>
And add whatever icons you want :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With