活动内容中的Android菜单按钮

时间:2014-02-27 18:13:37

标签: android menuitem

我的问题: 如何在Google Play中获得此类效果?

以下是图片:

enter image description here enter image description here

红色圆圈表示我的意思。

1 个答案:

答案 0 :(得分:1)

正如codeMagic评论的那样,正确的方法是使用PopupMenu,如下所示:

ImageView mOptions = (ImageView) findViewById(R.id.image); //the image you want press and get the menu to pop up on
mOptions.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                PopupMenu menu = new PopupMenu(this, view); 
                MenuInflater inflate = menu.getMenuInflater();
                inflate.inflate(R.menu.simple_menu, menu.getMenu()); //inflate simple_menu, a menu list you created in resources
                menu.setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        //handle menu clicks in here
                        return false;
                    }

                });
                menu.show();
            }

});