Remove error from main.xml file in menu - android

I've been getting an error in main.xml file which is in menu folder. R.java isn't generated. The error is on the last line of xml code. I have tried everything...
<?xml version="1.0" encoding="utf-8"?>
<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"/>
</menu>

Put this line in strings.xml inside /res/values directory
<string name="action_settings">Your String Here</string>

Well first of all, if you know basic html, you should know that every tag has an opening tag and a closing tag. That being said, in your code, you close the item tag but you forgot to closs the menu tag :-
<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"/>
</menu>

Cut your code from your xml-file and paste it in an normal text editor, notepad or gedit or something like this. Copy it back to your xml-file. Sometimes this helps.

Related

Error inflating class android.support.v7.internal.view.menu.ExpandedMenuView

i am trying to mage a lollipop app and solved my problems with tabs and style problems, but now i got a error i didn't see before and got no solution by other posts. i don't really know what happens there.
also i am using stack overflow first time to ask a question and i don't really know what all of my code u need for this issue.
thats my
menu_main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
<item
android:id="#+id/action_share"
android:title="#string/share"
android:orderInCategory="99"
app:showAsAction="always"
android:icon="#android:drawable/ic_menu_share"/>
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="never"/>
see this pastebin for the error
Seems that this doesn't exist:
android:icon="#android:drawable/ic_menu_share"/>
Are you sure that this exists? You could copy that drawable in your drawable folder and use
android:icon="#drawable/ic_menu_share"/>
instead.

Android Studio Action Bar logo display

I am trying to display a permanent small logo on the left size of the ActionBar, but I can't find how to do so. Please help me find a solution.
<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="com.redislabs.app.redis.infoIntent">
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
</menu>
There is a place to Specify your Logo in the
<application>
tag. This is located in your Manifest.xml file for your app. The value should be set to locate a drawable resource.
<application
android:logo="drawable resource">
I hope this helps!
Happy Coding! Leave a comment if you have any questions.

I have a error while creating an item in my menu?

<?xml version="1.0" encoding="UTF-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/test"
android:icon="#drawable/ic_lanucherxx.png" // error
android:title="#string/news"
android:showAsAction="ifRoom"/>
<item android:id="#+id/test2"
android:icon="#drawable/we.png" //error
android:title="#string/newss2"
android:showAsAction="ifRoom"/>
here is the xml file . the error says that there are no such images in the drawable folder . But i have made sure that that required images are present in all of those drawables folders .
Thank you for your time .
don't use extension .png
just remove it and try once i hope it solves your problem

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

Categories

Resources