Can't access android/drawable Icon-Resource

safari picture safari · Dec 5, 2011 · Viewed 18.4k times · Source

I'm creating a Optionsmenu, for that I use the Android Icon-Resource. But I can't access them, what am I doing wrong. What do I need to change?

Here's the Code of my menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@+id/Videos"
          android:icon="@android/drawable/ic_menu_view"
          android:title="Videos" />

    <item android:id="@+id/Bio"
          android:icon="@android/drawable/ic_menu_friendlist"
          android:title="Biographie" />

    <item android:id="@+id/Support"
          android:icon="@android/drawable/ic_menu_star"
          android:title="Support" />

</menu>

thank you for the help in advance!

Answer

user658042 picture user658042 · Dec 5, 2011

You are almost correct, when accessing framework resources you have to prefix the resource type with android: since you are using the android package here. Which means it should not be

android:icon="@android/drawable/ic_menu_view"

but

android:icon="@android:drawable/ic_menu_view"

instead for example (note the colon between android and drawable instead of a forward slash).


Also note that you can't access some resources, since they are not public, such as the ic_menu_star you are using here. You have to copy them to your projects drawable folders, which means you have to access them via a normal @drawable/ic_menu_star after doing that. See this question for reference.