androidactionbarsherlocktitlebarcommonsware

How to get options from the options menu into title bar ActionBar Sherlock android


I am trying to get my options to show up in the Title Bar. I'm using ActionBarSherlock and I can figure out how to remove the title in the title bar, but would like to replace the text with 2 options from my options menu.

I'm using this code, EmpubLite as an example for my application, but I can't figure out how Mark (the commonsware guy) got the icons from his options menu in the title bar. My options show up at the bottom in the action bar and this is taking up unnecessary room on the screen. I've been looking through examples here, but can't seem to find out exactly how to get options in the title bar. I'm hoping Mark (or someone) can explain.


Solution

  • would like to replace the text with 2 options from my options menu

    Um, unless that happens automatically by removing the title, I suspect that's not possible.

    but I can't figure out how Mark (the commonsware guy) got the icons from his options menu in the title bar

    Well, you see, that's covered in this delightful little book... :-)

    More seriously, android:showAsAction controls whether items should be in the overflow area (never), should be in the action bar (ifRoom), or really really should be in the action bar (always). That being said, always is a hint, not a demand, and the OS may still put your action bar items in the overflow on smaller screen sizes.

    You did not state which of the EmPubLite series you are experimenting with. Early on, the items are all set to never:

    <menu xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item
            android:id="@+id/help"
            android:icon="@android:drawable/ic_menu_help"
            android:showAsAction="never"
            android:title="@string/help"/>
        <item
            android:id="@+id/about"
            android:icon="@android:drawable/ic_menu_info_details"
            android:showAsAction="never"
            android:title="@string/about">
        </item>
    
    </menu>
    

    By the end of the series, we have some that ideally go into the action bar:

    <menu xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item
            android:id="@+id/notes"
            android:icon="@android:drawable/ic_menu_edit"
            android:showAsAction="ifRoom|withText"
            android:title="@string/notes">
        </item>
        <item
            android:id="@+id/update"
            android:icon="@android:drawable/ic_menu_save"
            android:showAsAction="ifRoom|withText"
            android:title="@string/download_update">
        </item>
        <item
            android:id="@+id/settings"
            android:icon="@android:drawable/ic_menu_preferences"
            android:showAsAction="never"
            android:title="@string/settings">
        </item>
        <item
            android:id="@+id/help"
            android:icon="@android:drawable/ic_menu_help"
            android:showAsAction="never"
            android:title="@string/help">
        </item>
        <item
            android:id="@+id/about"
            android:icon="@android:drawable/ic_menu_info_details"
            android:showAsAction="never"
            android:title="@string/about">
        </item>
    
    </menu>
    

    My options show up at the bottom in the action bar and this is taking up unnecessary room on the screen.

    You have android:uiOptions="splitActionBarWhenNarrow" set in your manifest somewhere, then.