我正在通過Android tutorial工作,無法讓我的搜索圖標顯示在我的操作欄中。無法將ic_action_search.png顯示在操作欄中
我不知道我錯過了什麼,但是新的,所以我不知道在哪裏看。
這是我main_activity_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>
這是我MainActivity.java
文件:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
我已經下載了ic_action_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>
還有什麼地方可以檢查以確定爲什麼搜索圖標不會出現在操作欄中?
**編輯**
繼周杰倫的建議,下面我已經改變了main_activity_actions.xml
以下內容。這會將字符串值放入操作欄中,而不是圖標。 android知道自動查找圖像文件夾嗎?
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto">
<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
yourapp:icon="@drawable/ic_action_search"
android:title="@string/action_search"
yourapp:showAsAction="always" />
<!-- Settings, hsould awlays be in teh overflow -->
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:showAsAction="never" />
</menu>
請按照這個教程http://www.vogella.com/tutorials/AndroidActionBar/article.html – Rohit
你需要從這裏添加一個庫下載http://actionbarsherlock.com – Rohit