1

I have been looking online for a while, and there are very little tutorials on how to do this. Even the google docs have very vague info on how to put this stuff up there! I am sure its subtle, but I can't understand the terminology because I am still fairly new to Android. I would like to be able to get the Action Overflow icon to the right side of the ActionBar. Putting the view control was pretty understandable using the docs and example code when creating a project, but it does not have one for the Action Overflow. Thanks in advance!

Edit: I should probably elaborate. I would like the menus to default being under the action overflow. I found an eye opener answer to a similar question, but it only tells you how to put the menus at the top. How can I force them to go under the list? Is it even possible to force that? Thanks!

Andy
  • 10,553
  • 21
  • 75
  • 125

1 Answers1

4

If you use API-11, it's not problem. If lower I am inviting you to this topic : The best way to create drop down menu in android 2.x like in ICS

In the case when API-11 and higher you must :

  1. Create menu xml like this :

         <?xml version="1.0" encoding="utf-8"?>
         <menu xmlns:android="http://schemas.android.com/apk/res/android" >
    
            <item
                android:id="@+id/item_refresh"
                android:icon="@drawable/ic_menu_refresh"
                android:title="Refresh"
                android:showAsAction="ifRoom|withText" />
    
            <item
                android:id="@+id/item_save"
                android:icon="@drawable/ic_menu_save"
                android:title="Save"
                android:showAsAction="ifRoom|withText" />
        </menu>
    

And create code like this :

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // gets the activity's default ActionBar
    ActionBar actionBar = getActionBar();
    actionBar.show();
    actionBar.setDisplayHomeAsUpEnabled(true);
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item){
    switch(item.getItemId()) {
    case R.id.item_refresh:
        //click on refresh item
        break;
    case R.id.item_save:
        //click on save item
        break;
    }
    return true;
}

Good Luck!

Community
  • 1
  • 1
Ilya Demidov
  • 3,275
  • 2
  • 26
  • 38
  • Nope, its 15! So how can I accomplish it? – Andy Jul 23 '12 at 05:15
  • Just ran what you gave me in various different ways. None of accomplished what I need :/ It puts them up there all right, but its doesn't make them into action overflows. – Andy Jul 23 '12 at 05:45
  • Wait, does it matter if I am running it on an emulator rather than on a device? – Andy Jul 23 '12 at 05:46
  • Nope, not working. I am tweaking the Android example that it automakes for you when creating a project with what you just said. Not creating a spinner like effect to the menus when they can't be shown since thats the action overflow look and feel. – Andy Jul 23 '12 at 05:57
  • Ok. You see ActionBar and one has menu button. You click it and overflow menu is shown or after click do nothing? Where is problem? – Ilya Demidov Jul 23 '12 at 10:02
  • No, the Action Overflow menu in the top right is not showing. The menus are shown at the top i there is room. Otherwise I need to press menu to have the rest show up. I want all the extras to show up in the Action Overflow menu on the top right – Andy Jul 23 '12 at 19:28
  • Damn, I finally had a chance to test it on an actual device, and it seems like it does matter if you do it on a emulator or a device. On the emulator it doesn't put the Action Overflow design at the top automatically, but on a device it does. So I guess it solves my problem in that manner. Thank you. – Andy Jul 23 '12 at 20:51