I have been trying to figure this out for quite some time right now. I've looked all over this site and many others, and can't find anything that works. I simply want icons next to each item in my navigation drawer. I am currently using the method that Google's navigation drawer sample app uses.
in the MainActivity.java I have the following:
mColorTitles = getResources().getStringArray(R.array.colors_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mColorIcons = getResources().getStringArray(R.array.color_icons);
adapter = new ArrayAdapter<String>(this, R.layout.drawer_list_item, mColorTitles);
// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// set up the drawer's list view with items and click listener
mDrawerList.setAdapter(adapter);
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
my drawer_list_item.xml:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:paddingRight="16dp"
android:textColor="#000"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeightSmall"/>
it currently just makes the navigation drawer display the color titles from the array. I have the icons that I want in another array, and they follow the exact same order as I want them associated with the colors. I just have no idea how to even begin inserting the icons from that array into the navigation items
if it helps, here's what my arrays look like in my strings.xml (not full code)
<string-array name="colors_array">
<item>Home</item>
<item>Cherry</item>
<item>Crimson</item>
...
<array name="color_icons">
<item>@drawable/homeicon</item>
<item>@drawable/cherryicon</item>
<item>@drawable/crimsonicon</item>
...
I've tried putting a drawable in the drawer_list_item, which works, but (of course) it always puts the same one in there. I could not think of a way to change it according to the color. I am relatively new to android programming, so if I am missing something simple, I'm sorry. If you could help me out, I would greatly appreciate it, as this is basically the last thing I need to do before I publish my application to the Play Store. Thanks in advance!