Can't find the ActionBar resource icon - android

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

Related

i can't add the menu icons to the tool bar in visual studio xamarin

it seems that what ever i did i cant set the icons visible to the tool bar, i've tried to do researches on many platforms, but nothing helped.
here is the xml menu:
<?xml version="1.0" encoding="utf-8" ?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/event_ic"
android:icon="#mipmap/ic_event"
android:title="profile"
android:showAsAction="always"
/>
<item
android:id="#+id/details_menu"
android:title="details"
android:showAsAction="never"/>
</menu>
you can see that even if i set the android:showAsAction to always, i still get the event item in the pop up menu without the icon.

Why is Android Studio complaining about android:layout_width and layout_height in my simple menu?

I have an app that builds just fine when I build it with ant. But when I import the app into Android Studio, it gives me this error message. Geezzz I really wish I could cut-n-paste text from Android Studio :( so please excuse my screen shot.
Here's my menu.xml file:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Single menu item
Set id, icon and Title for each menu item
-->
<item android:id="#+id/menu_exit"
android:checkable="true"
android:title="Exit" />
</menu>
#Luksprog's comment The IDE it's complaining because you put your menu file inside the layout folder so the IDE thinks that is a layout file.
You should put menu file under res/menu/menu.xml
For more details about menu resource
https://developer.android.com/guide/topics/resources/menu-resource.html
https://developer.android.com/guide/topics/ui/menus.html

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

icon error in Android actcionbar xml

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

Categories

Resources