Android – how to place item icons in the navigation drawer
•
Android
I'm developing an application that uses the navigation drawer. When I try to place the item icon, it provides me with the path of the image, such as RES / drawale / BG. JPG ". I don't know what to do
Here are my main activity codes:
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);
This is my string. XML code
<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>
resolvent:
Add the following code in the navigationview of XML:
app:menu="@menu/drawer_menu_icons"
Then create a new XML file named "painter_menu_icons" in the menu folder and do the following:
<?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 any icons you want:)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码