2013-09-25 37 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