适当的替代PopupMenu的为pre-蜂窝

适当的替代PopupMenu的为pre-蜂窝

问题描述:

我实现 PopupMenu的因为这是$ P $后显示的菜单pssing在动作条的项目。我想知道11之前有什么替代品存在的SDK版本?

I've implemented PopupMenu for a menu that is displayed after pressing an item on the ActionBar. I am wondering what alternatives there are for SDK versions before 11?

可能使用类似的东西的上下文菜单。你有什么想法?

Possibly use something resembling a context menu. What are your thoughts?

我目前的实施虽然是加载一个新的活动的菜单项。

My current implementation though, is to load a new Activity with the menu items.

由于@sastraxi建议,一个好的解决办法是使用 AlertDialog CHOICE_MODE_SINGLE

As @sastraxi suggested, a good solution is using an AlertDialog with CHOICE_MODE_SINGLE.

AlertDialog.Builder builder = new AlertDialog.Builder(MyAndroidAppActivity.this);
builder.setTitle("Pick color");
builder.setItems(R.array.colors, new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int which) {
           // The 'which' argument contains the index position
           // of the selected item
       }
});
builder.setInverseBackgroundForced(true);
builder.create();
builder.show();

和中的strings.xml文件。

And the strings.xml file.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="colors">
        <item >blue</item>
        <item >white</item>
    </string-array>
</resources>

参考:添加列表