Search code examples
androidactionbarsherlock

ActionBarShelock duplicates actionbar actions on hardware menu key press


I'm developing an app which supports APIS 9 to 17.

It also has a Navigation Drawer and for the action bar I use ActionBarSherlock. The problem comes when I press the menu hardware button (API <= 10). The actions displayed in the actionbar are duplicated. How to fix this issue?

Here's my code to inflate the menu

public boolean onPrepareOptionsMenu(Menu menu) {
    MenuInflater inflater = getSupportMenuInflater();
    inflater.inflate(R.menu.menu_content_action_menu, menu);
return true;        
}

And my menu_content_action_menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/send_order_action"
        android:icon="@drawable/ic_navigation_accept"
        android:showAsAction="ifRoom|withText"
        android:title="@string/send_order_button_text">
    </item>
</menu>

Hope you can help me.


Solution

  • Use your code in the onCreateOptionsMenu() implementation instead.

    public boolean onCreateOptionsMenu(final Menu menu) {
        getSupportMenuInflater().inflate(R.menu.menu_content_action_menu, menu);
        return true;
    }