Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8352505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:58:48+00:00 2026-06-09T08:58:48+00:00

Should be simple enough but might not be. When using action bar in Android

  • 0

Should be simple enough but might not be.

When using action bar in Android 3.0+ you have the option of defining your menu items in XML or in code. I prefer to code them in xml as action bars feel more UI based than functional.

On an average day, you would use this to inflate the xml into a menu

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    // Menu is defined inside 'res/menu/...xml
    getMenuInflater().inflate(R.menu.activity_home, menu);
    return true;
}

And your XML file would look like this

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/menu_settings"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/menu_settings"/>
    <item
        android:id="@+id/menu_item_menu"
        android:icon="@drawable/menu_off_128"
        android:showAsAction="ifRoom|withText"
        android:title="@string/inbox_string"/>
    <item
        android:id="@+id/menu_item_gallery"
        android:icon="@drawable/gallery_off_128"
        android:showAsAction="ifRoom|withText"
        android:title="@string/gallery_string"/>
    <item
        android:id="@+id/menu_item_inbox"
        android:icon="@drawable/inbox_off_128"
        android:showAsAction="ifRoom|withText"
        android:title="@string/inbox_string"/>
    <item
        android:id="@+id/menu_item_contact"
        android:icon="@drawable/phone_off_128"
        android:showAsAction="ifRoom|withText"
        android:title="@string/contact_string"/>

</menu>

Right now, I’m faced with the problem of making an actionbar backwards compatible and actionbarsherlock seems to be the most pleasant to use and popular.
So I tried the above with actionbarsherlock and sadly there are compile time issues.

Namely that the Menu class returned by the inflater is from ‘Android.view.menu’ and not the ‘com.actionbarsherlock.menu’. I went digging through the samples on github but all of them have the menu defined in code.

So has anyone manged to get an actionbarsherlock menu working with an XML file based layout?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:58:51+00:00Added an answer on June 9, 2026 at 8:58 am

    try this

        @Override
        public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
            getSupportMenuInflater().inflate(R.menu.your_menu, menu);
            return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

should be simple right? but have not found any anwsers :
This should seem simple enough, but can't figure it out. I was porting a
This should be a simple answer. I'm just not knowledgeable enough in CSS to
This should be simple, but I'm getting confused. I have a parent/child tables -
This should be simple task but i am not been able to find the
Simple enough, At the top left hand corner of the action bar sits the
Should be simple but I couldn't find the answer, I would like to place
It should be simple to create JavaScript intepreter in JavaScript using eval . I
This should be simple, but the answer is eluding me. If I've got a
This should be simple, yet I can't get it to work. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.