Android Development: Unable to create an icon @drawable/ic_action_search

pencilshree picture pencilshree · Aug 7, 2013 · Viewed 41.2k times · Source

I am new to Android Development. I was just following the basic turorial on developer.android.com to create my first application.

As I was creating the Action BAr, I had to add this Search button to it. I created the menu xml and this is what I had written on it.

<!-- 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" />

Now my question is on this part of the XML

android:icon="@drawable/ic_action_search"

I get a compilation error in eclipse, which says,

error: Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_action_search').

I checked on developer.android.com and also googled it out, but I'm just not able to locate a solution.

I need to solve this problem. As always, I am able to skip this part of the XML and what I get is just plain text "SEARCH", but the icon will definitely look better.

Answer

dturvene picture dturvene · Sep 15, 2013

Here is the easy way if you're using Eclipse:

  • Ctrl+N (emacs keybindings) to open the file wizard
    • 'File | New | Image Asset' in Android Studio
  • Select Android, "Android Icon Set"
  • Edit name ic_action_xx, click Next
  • Clipart, choose the icon you want
  • Select theme (Holo Light means a light background, Holo Dark means a dark background)

Eclipse will automatically populate the res/drawable-* directories with the new icon, scaled to the directory size. No need to download anything, understand PNG or copy the icon into multiple directories.

I use the file wizard A LOT.