澄清在android.R.drawable“私人”可绘 [英] clarification on 'private' drawables in android.R.drawable
问题描述
我想提出一个应用程序的菜单,并指出这个有用的资源其中列出了所有的可绘制的是Android 2.0的JAR的一部分。考虑到使用的例子是
myMenuItem.setIcon(android.R.drawable.ic_menu_save);
不幸的是,一个我想要的(和大多数名单)不可用默认情况下。我得到
android.R.drawable.ic_menu_login不能得到解决
当我尝试设置菜单项的图像:
@覆盖
公共布尔onCreateOptionsMenu(功能菜单){
//添加两个例子菜单按钮
INT的groupId = 0;
INT menuItemOrder = Menu.NONE;
INT menuItemId = 1;
字符串menuItemText =添加登录信息;
菜单项菜单项= menu.add(的groupId,menuItemId,menuItemOrder,menuItemText);
menuItem.setIcon(android.R.drawable.ic_menu_login)
做了一些变化,最近的Android版本?看来,其中大部分是目前私人资源......无法找到很多信息就这一点,但我发现了一些建议:
有用于访问私人 资源。不要使用它,因为这些 私人资源往往 删除/重命名/等。使用它会 最有可能打破在您的应用程序 未来的。
他们为什么要改变资源名称呢?(他们身后的照片肯定,但叫什么名字?)我如何进入ic_menu_login呢?有没有更好的理由不低于上述?
我如何进入ic_menu_login呢?
它复制到你的应用程序。你可以找到所有的人都在你的SDK安装,特别是在 $ ANDROID_HOME /平台/ $ API /数据/ RES /
,其中 $ ANDROID_HOME
是只要你安装了SDK和 $ API
一些Android的水平(例如,的Android 2.1
)。
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?
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
).
这篇关于澄清在android.R.drawable“私人”可绘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!