0

I am following the tutorial on the developer website to implement an action menu bar, and I cant seem to get the icon to be drawn. http://developer.android.com/training/basics/actionbar/adding-buttons.html

Here is what I have so far...

res/menu/main_activity_actions

<?xml version="1.0" encoding="utf-8"?>
<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="ifRoom" />
    <!-- Settings, should always be in the overflow -->
    <item android:id="@+id/action_settings"
          android:title="@string/action_settings"
          android:showAsAction="never" />
</menu>

Then I added that menu to the main activity

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_activity_actions, menu);
    return super.onCreateOptionsMenu(menu);
}

I am pretty sure the icon can be found because I added it in all res/drawable-* folders enter image description here

Then when I run the virtual device this is what I get

enter image description here

As you can see, the 2 menu items are there, but search has no icon like it does in the tutorial. Heres what it's supposedly supposed to look like

enter image description here

2

1 Answer 1

0

I have been going through the tutorials as well, and ran into the same difficulty. Here is what I found.

I spent a few hours trying the various technical solutions given for the problem. None of them made sense given my context. I tried a few things that seemed to suggest themselves to no avail. Then I found another possible solution, and although quite a bit simpler, perhaps harder to debug.

Make sure that the icons you provide are from the action bar icons in the path: holo_dark -> 01_core_search.

The holo_light icons were the same color as the background of my device and so appeared as if not present. Press on the screen in that area, and the icon does appear because the background color changes with selection of the menu item.

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.