ActionBar PopuMenu

PopupMenu

popupmenu可以非常方便得实现在指定view下弹出一个菜单,实现类似ActionBar中的效果.

public void showPopupMenu(View view){
        final PopupAdapter adapter = (PopupAdapter) getListAdapter();
        final String item = (String) view.getTag();

        PopupMenu popup = new PopupMenu(getActivity(), view);

        popup.getMenuInflater().inflate(R.menu.popup, popup.getMenu());

        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {
                switch (menuItem.getItemId()){
                    case R.id.menu_remove:
                        adapter.remove(item);
                        return true;
                }
                return false;
            }
        });
        popup.show();
    }
posted @ 2016-11-26 16:50  ivyxjc  阅读(86)  评论(0编辑  收藏  举报