Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add item to the top ActionBar?

I would like to add new icon to the top action bar, bet instead of adding to the top, the icon appear on the bottom of the screen. How can I add item to the top ActionBar?

XML:

<menu xmlns:android="http://schemas.android.com/apk/res/android">    
    <item android:id="@+id/preferences"
        android:icon="@drawable/preferences"    
        android:title="Preferences"
        android:showAsAction="always|withText"/>

    <item android:id="@+id/help"
        android:title="Help"
        android:icon="@drawable/ic_action_search" />    
</menu>

Java:

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.activity_ygo_main, menu);
    return true;
}
like image 733
OHLÁLÁ Avatar asked Aug 01 '12 16:08

OHLÁLÁ


2 Answers

Taken from http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar

To enable split action bar, simply add uiOptions="splitActionBarWhenNarrow" to your or manifest element.

So if you want to have an item in the top. Make sure that this line is NOT in your code.

like image 95
Frank Sposaro Avatar answered Oct 14 '22 16:10

Frank Sposaro


Check if you have android:uiOptions="splitActionBarWhenNarrow" in the activity definition in your AndroidManifest.xml. That's what makes action bar split to the bottom.

Check ActionBarSherlock for what you are doing. It will provide ActionBar functionality on the older android versions and will use native ActionBar when it's supported. It has sample application showcasing most of its settings http://actionbarsherlock.com/index.html

like image 36
mykola Avatar answered Oct 14 '22 16:10

mykola