androidandroid-actionbarandroid-optionsmenu

Text or Icon in action bar, stuck with the 3 dots


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:


Solution

  • 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.