2

I'm trying to add the Overflow Menu that android provides on my custom title bar but it does not seem to be appearing

Here is the code in my activity

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.overflow_menu, menu);
    return true;
}

in my .xml

     <?xml version="1.0" encoding="utf-8"?>
     <menu xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:id="@+id/settings" android:title="Settings" />
     <item android:id="@+id/help" android:title="Help" />
     </menu>

custom title bar code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"   
android:layout_height="44dp"   
android:orientation="horizontal"   
android:gravity="center_vertical"
android:background="#000000"   
>
<ImageView
    android:id="@+id/indicator"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="left"              
    android:src="@drawable/indicator"
    android:layout_marginRight="3dip"
     />

   <ImageView
    android:id="@+id/indicator"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="left"              
    android:src="@drawable/launcher_blue_tile"
    android:layout_marginRight="5dip"
     />

    <TextView              
    android:id="@+id/titleHeading"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/app_name"
    style="@style/titleBarHeading"

    /> 

Android manifest

    <activity
        android:name=".ILaneMainMenuActivity"
        android:icon="@drawable/indicator"
        android:label="@string/app_name"
        android:theme="@style/appTheme">

    </activity>

I Have looked in the documentation that Google provides as well as multiple resources online and can not find a solution. Any help will be much appreciated!

3
  • 2
    What is your "custom title bar", specifically? Commented Mar 1, 2013 at 20:43
  • edited to show the title bar as well as the manifest it is implemented Commented Mar 1, 2013 at 20:47
  • And I mean is that I created the title bar and it is not on of the android themes Commented Mar 1, 2013 at 20:54

2 Answers 2

1

If you are using the action bar, the overflow menu is triggered either by a "..." affordance on the right side of the action bar, or via the MENU button for devices with an off-screen MENU button.

If you are not using the action bar -- which is my guess -- then you will need to create your own menu system.

Sign up to request clarification or add additional context in comments.

3 Comments

Seriously? It is cruel of Android to offer a customizable action/title bar but leave the entire menu system to be implemented yourself if you do so.
@GreenBee: You seem to have misunderstood. The normal menu system works just fine (onCreateOptionsMenu(), etc.), and is now called the overflow. The trigger mechanism to display the overflow varies by device (MENU button for devices with it, ... affordance for those without). If you don't like the overflow, or are not showing an action bar, then you have to roll something yourself, as noted in the second paragraph of my answer.
Thanks. My titlebar code is almost similar to the one in the question above. As I use a custom title bar, it hides the default Android action bar and the so menu (affordance) is hidden. Perhaps I don't need a custom bar. Would you know of a way to have an image in the title/action bar (not just the square app icon that Android picks up by default). I just need a different image in there- slightly wider and having an custom bar and a menu system sounds like an overkill. Sorry for hijacking the comments. My ask is tiny, and so I thought I would ask it here rather than a new post.
1

How is your custom title bar supposed to fit in to the ActionBar/Menu arrangement? MenuInflater#inflate will create an ActionBar (post-Honeycomb / API 11+) or a Menu (pre-API-11), based on the items added to your /menu/overflow_menu.xml file.

The overflow menu (again, only in API 11+) will be added automatically if you have more items than will fit. You only have 2 items - Settings and Help - so unless it's a tiny screen, both items will likely fit, so no need for overflow.

You might be better off exploring the styling possibilities of the ActionBar - http://developer.android.com/guide/topics/ui/actionbar.html#Style - which includes allowing for customizing your icon & title, or even adding custom views/buttons. If you want to support earlier Android versions, you could have a style that only applies to pre-Honeycomb devices, but you'd have to manually add that layout to your Activities.

Another option would be ActionBarSherlock, which is highly recommended and widely used, but I have no personal experience with it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.