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.
Related
Previously, before using AppCompat, I was using SherlockActionBar to support Android 2.3.
The following menu works just perfect under SherlockActionBar
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_browser"
android:title="#string/menu_browser"
android:showAsAction="ifRoom"
android:icon="?attr/actionBarBrowserIcon"/>
<item
android:id="#+id/menu_share"
android:title="#string/menu_share"
android:showAsAction="ifRoom"
android:icon="?attr/actionBarShareIcon"/>
</menu>
However, even since migrating to AppCompat, I realize the above menu doesn't work. I need to use app namespace, in order to make it work.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/menu_browser"
android:title="#string/menu_browser"
app:showAsAction="ifRoom"
android:icon="?attr/actionBarBrowserIcon"/>
<item
android:id="#+id/menu_share"
android:title="#string/menu_share"
app:showAsAction="ifRoom"
android:icon="?attr/actionBarShareIcon"/>
</menu>
Why is this so? What is the difference comparing to SherlockActionBar, which makes app namespace unnecessary?
Attributes provided by libraries (or by the app itself) are suppose to be namespaced in order to avoid conflicts/collisions.
ActionBarSherlock masks this behavior by naming the attribute android:showAsAction. (As opposed to a showAsAction attribute in the android namespace): https://github.com/JakeWharton/ActionBarSherlock/blob/master/actionbarsherlock/res/values/abs__attrs.xml
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 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...
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.
I have a problem: I want to put a search Icon on the Action Bar. In Android Studio it shows it on the Action Bar, but when I open the App it only shows it in the menu..
Here is my xml code:
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
android:showAsAction="never" />
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:showAsAction="ifRoom"
android:title="#string/action_search"/>
I tried many things but it wont work. I hope you can help me.
It still doesn't work I really don't have a clue why.
You're not specifying your ActionView class, which is probably part of the problem. Here is the xml for a search action view that I use in one of my applications that works fine.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/search_user"
android:actionViewClass="android.widget.SearchView"
android:icon="#drawable/magnifing_glass"
android:showAsAction="ifRoom|collapseActionView"
android:title="#string/action_search"/>
</menu>
EDIT:
If you're not trying to use it as an ActionView, disregard the above and use showAsAction="always".
Your problem is either that there is not enough space on the action bar to display the icon, or your device has a dedicated menu button.