Reputation: 158
I'm making an android app in Eclipse. I want to place a text or icon in the action bar, but when I am writing in menu.xml, which looks like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/createnew"
android:orderInCategory="1"
android:showAsAction="ifRoom"
android:title="CREATE"/>
</menu>
it puts it in the options menu. I want to separate it.
I see this in the app when I run it: (sorry can't post pictures because I don't have enough rep)
I want to CREATE next to the option menu like this for example:
Upvotes: -1
Views: 1000
Reputation: 67189
Since you are using the AppCompat Actionbar, you need to use a custom namespaced showAsAction
attribute.
It should look something like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/createnew"
android:orderInCategory="1"
yourapp:showAsAction="ifRoom"
android:title="CREATE"/>
</menu>
Note that this uses yourapp:showAsAction
instead of android:showAsAction
. This is because the showAsAction
attribute is not available on pre-Honeycomb devices and is provided by the support library.
For more information, read the Action Bar developer guide.
Upvotes: 2
Reputation: 25060
It's caused by this line
android:showAsAction="ifRoom"
That tells Android to put it up there if it's going to fit nicely. If you want it up there no matter the fit use
android:showAsAction="always"
Upvotes: 0