Android Development: Unable to create an icon #drawable/ic_action_search - android

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.

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.

In Android studio:
Right click the Drawable folder > Select New > Image Asset
(Alternatively, click shift, shift and type 'Image Asset")
In the dialog which popped up click 'OK'
From the wizard you can customise the asset you require.
Choose if it's a Notification icon, Action bar icon or launcher icon. You can select icons from clipart, create icon from text or import an image from disk.
The wizard will take care of creating different resolutions for your new image.

You need an image called ic_action_search.png or ic_action_search.gif, for example. Paste this image in every res/drawable folder.

As others have advised, you need to have (put) the icon graphic, "ic_action_search.png" in the correct folder, which is "/res/drawable" You may have to move a graphic file for one or more of the "drawable" subfolders of "/res"
You can find the icon graphics (and others that you will, presumably, need in the future) at, (http://developer.android.com/design/downloads/index.html#action-bar-icon-pack)
Please note: do not use the "Core Icons/unstyled," in the package. Use the "All_Icons/holo_light," (most likely) or "All_icons/holo_dark."

The error means that you don't have an image called ic_action_search in your drawable folder.
You can download an image for search from Android Asset Studio if you like.

I suppose you copy pasted some example code, as other answers says you missed putting drawable into your resources. For testing you might use default android search icon:
android:icon="#android:drawable/ic_menu_search"
I am not sure if it is safe to use it in release apps

First think English is no my main language, i apologize for my typing. Ok let's go to the problem. All this works for me, i hope it works for you. I was following the same instructions from developer.android.com as you, and it didn't say that you have
to put it in both .xml, or i didn't see.
Because is too much stuff and is overwhelming, i know at first but i hope to get used to it soon. Under the folder: res/menu you have two.xml archive one for the main page and the other for the activity. What do you have to do is copy that you wrote to both .xml archive:
Display_message.xml
main.xml
remember the action bar goes along the way with the activity, as many as you have. That means if you add another activity, you have to paste this in the new one in order to void that error. By the way you already have the images int he their respective folder. if not, it going to pop the error again. I hope this was understandable and with sense.

An other way to add a new icon into your project in Android Studio (same as dturvene's in Eclipse)
1. Choose drawable directory; Alt + Insert or File/New...
2. Choose "Image Asset"
3. Select drawable\hdpi as your icon's destination
4. An option window will pop up. Select directory to your icon saved in your PC.
I just found the way to do it so I hope it help.

Related

xamarin: I can't add anything to the .Android section

In my project I want to add a menu bar. I have downloaded a menu icon now I want to add it under .Android -> Resources. Unfortunately I can't add anything (a prohibition sign appears as a mouse icon). I also tried to add only a png or another file which also does not work.
My project
The downloaded icons:
Does anyone know how I can add the files in the appropriate place?
Don't know if this is the case, but some times the projects lacks the actual 'Drawable' folder. Create the folder yourself from fileexlorer

My Android studio Drawable Resource Folder Imports in a very crowded manner

I'm currently following a tutorial, Currently, it is required to import multiple images drawable folders for different densities by simply copying and pasting it to android studio
picture of the Folder from which we import the images
Image of the tutorial after pasting
and This is Me after pasting
as you can see me pasting, Creates a directory for each image with the corresponding density
which makes the drawable folder very crowded, so am I doing something wrong ? or this is new in android studio ? because I remember an old project of mine which didn't import it like that, Thank you for your time and be patient with me
There is actually no problem. It is the view that you are using which is different. If you want yours to look like the on in the tutorial, you should go right to the top of that window (that shows you) and look for the android "face" or sign with the word "Android" next to it and an arrow pointing downwards and click on that android sign. A dropdown menu will open up and then you should choose the "Project" option option. Now your files will look like the ones in the tutorials.
Check this website if you are confused :
https://developer.android.com/studio/projects
You might be using Project View , try changing it to Android View.
You can find it on the top-left corner.

Where do I find the styles.xml file?

I have a very simple application that runs an html file. I really want to change the color of the status bar, because the standard top and bottom in black is horrible for the color palette of the page shown. I have no idea about Android and I can't start learning now, but I tried to follow the answers, as in this question here at Stack Overflow: How to change the status bar color in android. However, I can't even find the styles.xml file that is indicated to put the parameters inside. I tried to create the "value" folder with the styles.xml file inside, but it only corrupted the app, as I imagined it would happen.
This is how the file tree of my app (generated by the Website to APK Builder) is seen:
What do I do to accomplish this? Please help me!
Note: I tried the edits through Android Studio.
For more details, here's the .apk: Google Drive
Change project structure to Android.
Follow below image
Now getting structure like below Image:
Here is style.xml file present under res->values
If not getting style.xml file, then Create new file res->values->New->Value Resource file
I hope this helps you
No need styles.xml file in the new Android Studio. Goto your project file view: Res>Values>Themes folder.
Open themes.xml file change actionbar.
android studio live example
You can find it in your resource directory
res/values/styles.xml
Right click on res - new - package - write the name of package as values - in the drop down of folder type, select values - ok.
The values folder is created!
Right click on values package - new - Android Resource Xml file - write name as styles in the name section - Ok.

My laucher icon is glitching, its cut into half

as title says, my ic_launcher cut into half, here is the pic
this is the original:
how did this happen, is there any suggestion?
Try using a png file.
or simple right click on your project, select new and then choose Image Asset. Now you will have plenty of options.
It should work
I suggest you use the following method.
Right click on drawable: new ->Image Asset
Select Launcher Icon in asset type
Select the path of the image you want to use as icon and keep the name as ic_launcher only.
next and finish.
You can customize it using the different checkboxes and options.
This should work for the launcher icons.
ps: not enough reputation to comment, so posting as a new answer. :/

Floating action button android change icon

I followed a template on android studio to create a navigation drawer app. As you know it creates an initial activity with a floating action button and the email icon in it. I just want to change it to a plus sign. Here is the problem. It turns out there is no plus sign available as the ones I can see in every single example ( There is just one I can use but then the plus sign color is green, and I want it white! ).
I followed this steps how to download Material icons , I get the icon ic_plus, and I put every single file in its correspondent folder ( drawables, drawables-hdpi... ).
Problem is when I try to use it here:
The name turns red as it can't find it. As I said, I copied all files one by one to its correspondent drawable folder. I even tried this drawable importer
but the same happen.
What am I missing? And why plus sign icon it is not shipped as default icon, as for example the e-mail icon is, as I can see it in every single app using floating action button? I use Android Studio 1.5. Thank you!
EDITED
Looks like images are correctly placed in correspondent folders because if I try to use it on menu bar, I can find it through #drawables/ . Still don't know why I can't do the same for the floating action button. Ideas?
Put your image in the drawable folder.
Use the design editor and when you click on the FAB scroll down to the src and click that little square button with 3 dots on the right side to pull up all your options. You should be able to search for the name of the icon you uploaded and select it from here.
I tried to type in my file name using text editor and it couldn't find my image either.

Categories

Resources