Android 无法在操作栏中显示ic_action_search.png

Android 无法在操作栏中显示ic_action_search.png,android,android-layout,Android,Android Layout,我正在使用,无法使我的搜索图标显示在我的操作栏中 我不确定我错过了什么,但我是新的,所以我不知道去哪里找 这在我的main\u activity\u actions.xml中 <menu xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Search, should appear as action button --> <item android:id="@+id/a

我正在使用,无法使我的搜索图标显示在我的操作栏中

我不确定我错过了什么,但我是新的,所以我不知道去哪里找

这在我的
main\u activity\u actions.xml中

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <!--  Search, should appear as action button -->
    <item android:id="@+id/action_search"
        android:icon="@drawable/ic_action_search"
        android:title="@string/action_search"
        android:showAsAction="always" />

    <!--  Settings, hsould awlays be in teh overflow -->
    <item android:id="@+id/action_settings"
        android:title="@string/action_settings"
        android:showAsAction="never" />
</menu>
我已经下载了
ic\u action\u search.png
文件,并将它们分别放在以下目录中:

/home/user/workspace/MyFirstApp/res/drawable-hdpi
/home/user/workspace/MyFirstApp/res/drawable-mdpi
/home/user/workspace/MyFirstApp/res/drawable-xhdpi
/home/user/workspace/MyFirstApp/res/drawable-xxhdpi
当我通过Eclipse运行应用程序时,我确实在logcat控制台中看到了以下错误,但我不确定它们是否引用了png文件

<snip>
05-11 21:51:17.823: I/Adreno200-EGLSUB(32725): <ConfigWindowMatch:2087>: Format RGBA_8888.
05-11 21:51:17.833: D/memalloc(32725): ion: Mapped buffer base:0x506af000 size:1949696 offset:0 fd:59
05-11 21:51:17.833: E/(32725): Can't open file for reading
05-11 21:51:17.833: E/(32725): Can't open file for reading
05-11 21:51:17.843: D/OpenGLRenderer(32725): Enabling debug mode 0
<snip>

如果您错过了
xmlns:yourapp=”http://schemas.android.com/apk/res-auto“
将这一行添加到您的菜单,然后图像无法检查它。

我在尝试遵循教程时也遇到了此问题。我尝试了所有显示的解决方案,包括添加

xmlns:yourapp=”http://schemas.android.com/apk/res-auto“

什么都没用。我的图标仍然不会显示在ActionBar中,我最后注意到教程中有3个版本的styles.xml文件,而我的项目只有一个styles.xml文件

其他样式是res\values-v11文件夹中的:(styles.xml):

<resources>

<!--
    Base application theme for API 11+. This theme completely replaces
    AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
    <!-- API 11 theme customizations can go here. -->
</style>

在res\values-v14文件夹中:

<resources>

<!--
    Base application theme for API 14+. This theme completely replaces
    AppBaseTheme from BOTH res/values/styles.xml and
    res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <!-- API 14 theme customizations can go here. -->
</style>


当我把这两个文件放到我的res文件夹中时,它起了作用

最好的办法是下载搜索图标,或者出于这个原因,从谷歌开发者网站下载任何图标,并进行相应的修改


将图标图像保存在res/drawable文件夹中,然后刷新Android Studio。

按照本教程操作,您需要从此处添加库下载,这并非仅适用于Android版本的需要。添加该图标并不幸运,这两个项目仅显示在溢出中。如果您希望始终显示它,请替换Android:showAsAction=“始终”到yourapp:showasaaction=“always”。谢谢,即使将主要的_activity_actions.xml更改为具有
yourapp:showasaaction
它也不起作用。是否需要将
adroid:icon
更改为
yourapp:icon
?此外,我是否需要将图像放在其他文件夹/位置,或者上面列出的位置是否正确?
<resources>

<!--
    Base application theme for API 11+. This theme completely replaces
    AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
    <!-- API 11 theme customizations can go here. -->
</style>
<resources>

<!--
    Base application theme for API 14+. This theme completely replaces
    AppBaseTheme from BOTH res/values/styles.xml and
    res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <!-- API 14 theme customizations can go here. -->
</style>