0

I am working on my android app and now i am in the process of creating app settings menu. I have created a menu but I want to display the menu at the top of the screen rather at the bottom so I am looking for some help.

Thanks in advance.

Ali

Ali Abid
  • 41
  • 1
  • 7
  • 1
    Why not use the ActionBar instead of trying to change how the Options Menu is displayed? – Sam Nov 10 '12 at 18:06

1 Answers1

3

This is a tutorial for a quickAction Dialog, which you could use. - http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/

To make a default android popup menu without any libraries use the following code.

On the foutrh line, the layout that you specify is your menu layout (see below)

    public void showPopup(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.layout.menu, popup.getMenu());
    popup.show();
}

When you call this method, you need to do the following

    View p = (View)findViewById(R.id.view);
showPopup(p);

In this price of code, View p is the view at the location that you want to show the top corner of the menu. So if you happen to have a textview in the top corner, use that as the view to lodge your menu on.

For more info on this look here - android menu code not working To override the menu button function do the following

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ( keyCode == KeyEvent.KEYCODE_MENU ) {
        //Put the code for an action menu from the top here
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
Community
  • 1
  • 1
jcw
  • 5,132
  • 7
  • 45
  • 54
  • Thanks mate thats really a good example but i want to show the menu when users press "Menu" button from the phone and i dont want to add any button on the screen. – Ali Abid Nov 10 '12 at 18:19
  • See my edit, I am trying to find the code to make a popup list that looks like the default menu now – jcw Nov 10 '12 at 18:43
  • Hi JCW thanks for all your help. I am also considering to use ActionBar so lets see where i will end. Thanks for all your help and answers :) – Ali Abid Nov 10 '12 at 19:16