Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 298
pencilshree Avatar asked Aug 07 '13 03:08

pencilshree


People also ask

How to add icon to drawable in Android Studio?

Drag and drop your images directly onto the Resource Manager window in Android Studio. Alternatively, you can click the plus icon (+), choose Import Drawables, as shown in figure 3, and then select the files and folders that you want to import. Figure 3: Select Import Drawables from the dropdown menu.


1 Answers

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.

like image 75
dturvene Avatar answered Oct 13 '22 12:10

dturvene