Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clarification on 'private' drawables in android.R.drawable

I am making a menu for an app and was pointed to this useful resource which lists all the drawables that are part of the android 2.0 jar. the usage example given is

myMenuItem.setIcon(android.R.drawable.ic_menu_save);

Unfortunately, the one I want (and most of the list) are not available by default. I get

android.R.drawable.ic_menu_login cannot be resolved

when I try to set the menu item images:

    @Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Add two example menu buttons
    int groupId = 0;
    int menuItemOrder = Menu.NONE;

    int menuItemId = 1;
    String menuItemText = "Add Login Details";
    MenuItem menuItem = menu.add(groupId, menuItemId, menuItemOrder, menuItemText);
    menuItem.setIcon(android.R.drawable.ic_menu_login )

Did something change in recent android releases? It seems that most of these are now 'private resources'... couldn't find much info on this but I found some advice:

It is used to access private resources. Do not use it because these private resources are often removed/renamed/etc. Using it would most likely break your app in the future.

Why would they change the resource names anyway? (The images behind them sure, but the names?) How do I access ic_menu_login then? Is there a better reason not to than the above?

like image 830
edzillion Avatar asked Apr 14 '10 11:04

edzillion


1 Answers

How do I access ic_menu_login then?

Copy it into your application. You can find all of them in your SDK installation, specifically in $ANDROID_HOME/platforms/$API/data/res/, where $ANDROID_HOME is wherever you installed the SDK and $API is some Android level (e.g., android-2.1).

like image 180
CommonsWare Avatar answered Oct 21 '22 10:10

CommonsWare