感觉上下文菜单?

时间:2012-05-27 09:28:51

标签: android android-contextmenu sense

我注意到有些程序使用弹出工具栏来显示上下文菜单而不是实际的上下文菜单,例如Sense(参见图片:)

enter image description here

我将如何实施类似的东西?

2 个答案:

答案 0 :(得分:1)

它被称为快速动作弹出窗口,您必须自己创建它。

请参阅此LINK

示例代码段::

//Add action item
ActionItem addAction = new ActionItem();
addAction.setTitle("Add");
addAction.setIcon(getResources().getDrawable(R.drawable.ic_add));

//Accept action item
ActionItem accAction = new ActionItem();

accAction.setTitle("Accept");
accAction.setIcon(getResources().getDrawable(R.drawable.ic_accept));

//Upload action item
ActionItem upAction = new ActionItem();
upAction.setTitle("Upload");
upAction.setIcon(getResources().getDrawable(R.drawable.ic_up));

创建快速操作实例和设置侦听器

final QuickAction mQuickAction  = new QuickAction(this);

mQuickAction.addActionItem(addAction);
mQuickAction.addActionItem(accAction);
mQuickAction.addActionItem(upAction);

//setup the action item click listener
mQuickAction.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() {
    @Override
        public void onItemClick(int pos) {
        if (pos == 0) { //Add item selected
           Toast.makeText(Example1Activity.this, "Add item selected", Toast.LENGTH_SHORT).show();
        } else if (pos == 1) { //Accept item selected
           Toast.makeText(Example1Activity.this, "Accept item selected", Toast.LENGTH_SHORT).show();
        } else if (pos == 2) { //Upload item selected
           Toast.makeText(Example1Activity.this, "Upload items selected", Toast.LENGTH_SHORT).show();
        }
    }
});

答案 1 :(得分:1)

这些链接完全符合您的需求,就像这个弹出工具叫做QuickAction:

QuickAction

QuickAction Dialog

Green Droid QuickAction

QuickActionBar and GridAction

希望这会对你有所帮助