2013-09-25 34 views
2

全部,原谅我刚开始学习Android的开发,这是我第一次在我的Android应用中使用ActionBar。首先。 我正在关注tutorial以将ActionBar的资源添加到项目中。但IDE警告我找不到资源。请帮助查看我目前的设置。谢谢。找不到ActionBar资源图标

我已经下载并上传了所有的Icons。并复制res/drawable文件夹下的所有图标。

enter image description here

,我添加一个名为main_activity_actions.xml一个xml文件,低于该内容显示了文件夹res/menu下。

<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/Core_Icons/unstyled/hdpi/ic_action_search" 
      android:title="@string/action_search" 
      android:showAsAction="ifRoom" /> 
    <!-- Settings, should always be in the overflow --> 
    <item android:id="@+id/action_settings" 
      android:title="@string/action_settings" 
      android:showAsAction="never" /> 

</menu> 

有人能告诉我为什么IDE找不到图标ic_action_search.png?谢谢。

+0

尝试建立您的项目。项目 - >清洁 – Swayam

+0

你似乎在'res'文件夹中有一些错误。首先解决该问题。否则,你的项目将不会建立。 – Swayam

+0

@Swayam重建项目后错误仍然存​​在(无法找到图标)。谢谢。 –

回答

2

不幸的是,资源文件夹不支持目录层次结构(子文件夹),因此您需要将所有图标移动到父文件夹(drawable)。

然后像这样引用它:android:icon="@drawable/ic_action_search"

https://code.google.com/p/android/issues/detail?id=2018

+0

+1正确!错误消失了。谢谢你的帮助。 –

+0

没问题!这很烦人,因为它会让较大的项目难以管理,但这是现在的方式,直到他们修复它。 – ashatte