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

倖福魔咒の 提交于 2019-12-06 03:29:05

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/2636805/clarification-on-private-drawables-in-android-r-drawable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!