The best way to create drop down menu in android 2.x like in ICS

前端 未结 3 964
猫巷女王i
猫巷女王i 2020-12-09 05:31

I want to create button with drop down menu, like overflow menu button in ActionBar on ICS. I have problem because PopupMenu there isn\'t in android 2.x. The second way usin

相关标签:
3条回答
  • 2020-12-09 05:41

    If your purpose is to recreate an action bar, you could take a look at the ActionBarSherlock project, which backports thoses functionalities.

    If you want to be able to pop such a menu anywhere in your app, you could read the implementation of the MenuPopupHelper class implementation in the ActionBarSherlock project source code.

    0 讨论(0)
  • 2020-12-09 05:42

    An alternative to your requirement could be ,that you create a list view,, position it under your button & set it's visibility to invisible by default & when you click on the button you can toggle the listview's visibility .... for example

    button.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    if (LISTVIEW.isShown()) {
                        LISTVIEW.setVisibility(View.INVISIBLE);
                    } else {
                        LISTVIEW.setVisibility(View.VISIBLE);
                    }
    

    let me know if this helps...

    0 讨论(0)
  • 2020-12-09 06:03

    I use PopupWindow for that sort of thing. It's more work than a PopupMenu, where you just give it a Menu and respond to events with OnMenuItemClickListener.onMenuItemClick(). With a PopupWindow, you provide a content View and handle clicks at a somewhat lower level.

    Still, it gets the job done without too much trouble. The showAsDropDown() method allows you to anchor the popup to another View (position it appropriately as a drop-down or pop-up menu), just as you want. It's been around since API level 1 and works great for me on all my test devices.

    0 讨论(0)
提交回复
热议问题