java Android drawable ic_menu_star 不工作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6589753/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 16:30:24  来源:igfitidea点击:

Android drawable ic_menu_star not working?

javaandroid

提问by soren.qvist

I'm designing a menu in XML:

我正在设计一个 XML 菜单:

    <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:icon="@android:drawable/ic_menu_preferences" android:title="@string/menu_preferences" android:id="@+id/menu_preferences"/>
    <item android:id="@+id/menu_bookmarks" android:title="@string/menu_bookmarks" android:icon="@android:drawable/ic_menu_star"></item>
    <item android:title="@string/menu_history" android:id="@+id/menu_history" android:icon="@android:drawable/ic_menu_recent_history"></item>
</menu>

When I try to use the android drawbale ic_menu_star my eclipse throws an error:

当我尝试使用 android drawbale ic_menu_star 时,我的 eclipse 会抛出一个错误:

[2011-07-06 00:52:28 - Testapp] W/ResourceType( 1852): Bad XML block: header size 51 or total size 3342532 is larger than data size 0
[2011-07-06 00:52:28 - Testapp] C:\eclipseprojects\Testapp\res\menu\search_menu.xml:4: error: Error: Resource is not public. (at 'icon' with value '@android:drawable/ic_menu_star').

I've checked the android resources in my project and it is in there. I'm building my project on the android 2.1 framework. Is this a bug?

我已经检查了我的项目中的 android 资源,它就在那里。我正在 android 2.1 框架上构建我的项目。这是一个错误吗?

回答by Estel

Some drawables in the Android package aren't declared as public, and can't be referenced in this way.

Android 包中的一些 drawable 未声明为 public,不能以这种方式引用。

The only way to use this drawable is to copy it into your own drawable directory and reference it there.

使用这个 drawable 的唯一方法是将它复制到你自己的 drawable 目录中并在那里引用它。

Edit: Google have since added a pack of action bar icons to the Android Developer site.

编辑:Google 已经向Android 开发者站点添加了一组操作栏图标。

回答by AllDayAmazing

Best way to find the default ones in Android Studio and right click on /drawable folder -> New -> Image Asset and follow the steps, most likely the asset is in "ClipArt" enter image description here

在 Android Studio 中找到默认值的最佳方法并右键单击 /drawable 文件夹 -> 新建 -> 图像资源并按照步骤操作,资源很可能在“剪贴画”中 在此处输入图片说明