icon error in Android actcionbar xml - android

I am beginning android development and I am having problems making an action bar. Basically I am following some code form online and I am getting an error saying I do not have an icon:
error: Error: No resource found that matches the given name (at 'icon' with value '#drawable/ic_menu_search').
I did some research and thought my problem was I did not have all the extras downloaded from the android SDK. But after downloading all the extras it didnt work. I know I could just find the icon and download it, but I do not want to have to download all the icons individually, therefore I think I am missing something. My xml file I am getting the error with looks like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="#string/action_settings"/>
<item android:id="#+id/menu_search"
android:title="#string/menu_search"
android:icon="#drawable/ic_menu_search"
android:showAsAction="ifRoom|collapseActionView"
android:actionViewClass="android.widget.SearchView" />
</menu>
this is under menu>main.xml

If you want to use the android icon, you should add the android prefix after #. Change
#drawable/ic_menu_search
in
#android:drawable/ic_menu_search
#drawable looks inside the res/drawable* folder of your app. If you want to access to the android resources. strings/drawable/id you have to put the android prefix after the #. with that prefix you will access to the android.R class not to your.R class

Related

Android Studio: Trouble specifying drawable resource

I am trying to specify an menu icon for an Action Bar. I'm using Android Studio 1.2. My XML code follows:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="#+id/menu_connect"
android:icon="#drawable/ic_settings_bluetooth_white_24dp.png"
android:title="#string/menu_connect"
app:showAsAction="always"
/>
<item
android:id="#+id/menu_settings"
android:title="#string/menu_settings"
app:showAsAction="never"
/>
</menu>
The compiler complains about anything that I put after "android:icon=". Depending on what I've changed last, I get: "No resource found that matches the given name" or "String types not allowed" (among other errors).
I've tried suggestions from several posts. I cleared the Intellij cache and rebuilt everything and nothing changed. One post suggested that perhaps android:icon wasn't supported in earlier API versions so I set minSdkVersion to 23 (my current SDK version) in my module build script. I re-sync'd and again nothing changed.
I had some trouble figuring out how to set up the drawable directories for multiple resolution bitmaps. (Why doesn't Android Studio just create them when creating a new project?) I now have them (drawable-hdpi etc.) set up as siblings to the drawable directory. I think that's right. At least they appear to be correct in the Android directory view. Yeah, I'm a newbie.
Is there anything else that I can try?
Replace:
android:icon="#drawable/ic_settings_bluetooth_white_24dp.png"
with:
android:icon="#drawable/ic_settings_bluetooth_white_24dp"
You do not use file extensions when referring to resources from anywhere inside of Android.

Error: No resource found that matches the given name (at 'title' with value '#string/ action_search')

I am very new to android development with eclipse, and I encounter dozen of errors and problems. Here is the next one:
I am following a tutorial to learn android development on eclipse. I was following the example here to include actions xml (file res/menu/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="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:showAsAction="never" />
</menu>
The following line is marked with the error given in the title:
android:title="#string/action_search"
although I have added the following line to res/values/strings.xml:
<string name="action_search">SEARCH</string>
I even cleared the project. What is wrong now?
Addendum:
Not sure if this is related, the cause of my problem or caused by my problem: Every variable reference to 'R' has an error: 'R cannot be resolved to a variable'.
I have used AppCompact for implenting the action bar. Below is my menu xml code, please try with the code
<item
android:id="#+id/action_search"
android:icon="#drawable/icon_search"
android:title="#string/search"
yourapp:actionViewClass="android.support.v7.widget.SearchView"
yourapp:showAsAction="ifRoom|collapseActionView"/>
Rest of your xml view...

Android - custom tab bar icon on ActionBarSherlock produces error

I'm using ActionBarSherlock and HoloEverywhere in this project. The Main.xml is pretty simple and looks like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:showAsAction="ifRoom|withText"
android:title="#string/action_info_settings"
android:icon="#android:drawable/ic_menu_customsettings"/>
</menu>
I have ic_menu_customsettings.png in drawable-mdpi, drawable-hdpi, and drawable-xhdpi. I'm getting the following error:
Error: No resource found that matches the given name (at 'icon' with value '#android:drawable/ic_menu_customsettings').
Am I supposed to do something more than put the png files in those folders to make them accessible by the ActionBar?
The correct line is:
android:icon="#drawable/ic_menu_customsettings"/>

Android unable to load drawable image on Menu

I am following step by step instructions shared on development platform of google http://developer.android.com/training/basics/actionbar/index.html
But some how due to some reason I am not seeing ic_action_search.png on Menu bar in my simulator, though it is imported and copied on drawable-hdpi.
Listing down all options tried till now (using eclipse IDE):
Import image ic_action_search.png
Don't import image but copy it directly on folder
Size of image, I have copied it directly from Android_Design_Icons.zip suggested at https://developer.android.com/design/downloads/index.html
Recompile project by "Clean"
Deleting res in bin folder
Deleting R.java in gen folder
Creating whole project altogether again
Changing option android:showAsAction to "never", "always", "ifRoom"
Placing .png file at right place
Not using .jpg only .png
Using Support library
Using lower case to define file names
Added following to menu tag,
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.actionbar.MainActivity"
Added follwoing to item tag
android:actionViewClass="android.widget.SearchView"
My main_activity_actions.xml looks like,
<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="never" />
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:showAsAction="never" /></menu>
.... but still I cant see search image getting loaded up in menu bar. Though settings icon shows the action_search value defined in string.xml
I am not using Support Library Setup as of now, and android:minSdkVersion="11"
android:targetSdkVersion="19"
I need to show this, as there is something wrong here and as i go further I still cant load any other image. Please advise
You need to change the showAsAction as always or ifRoom to show the action icons in the menu bar.
If you set it to never , it will not be shown as an action menu. It will only show in PopupMenu
Change
android:showAsAction="never"
to
android:showAsAction="always"
append this line in your menu tag xmlns:yourapp="http://schemas.android.com/apk/res-auto"
and append these two lines in item tag
yourapp:actionViewClass="android.widget.SearchView"
yourapp:showAsAction="always"
i.e. use this layout
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<!-- Search / will display always -->
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
android:actionViewClass="android.widget.SearchView"
yourapp:actionViewClass="android.widget.SearchView"
yourapp:showAsAction="always"
android:showAsAction="always"/>

Can't find the ActionBar resource icon

All, Forgive me I just began to learn development of Android, It is the first time I used the ActionBar in my Android application. Firstly.
I was following the tutorial to add the resource of ActionBar to project. But the IDE alert me the resource can't be found. please help to review my current setup. thanks.
I had downloaded and upziped all the Icons. and copy all the icons under the res/drawable folder.
and I add a xml file named main_activity_actions.xml under the folder res/menu which content shows below.
<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/Core_Icons/unstyled/hdpi/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>
Could someone please tell me why IDE can't find the icon ic_action_search.png? thanks.
Unfortunately the resource folders do not support directory hierarchies (sub-folders), so you will need to move all icons to the parent folder (drawable).
Then reference it like this: android:icon="#drawable/ic_action_search"
https://code.google.com/p/android/issues/detail?id=2018

Categories

Resources