Appropriate alternative to PopupMenu for pre-Honeycomb

前端 未结 2 1967
感动是毒
感动是毒 2021-01-02 05:22

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?

2条回答
  •  误落风尘
    2021-01-02 05:35

    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();
    

    And the strings.xml file.

    
    
        
            blue
            white
        
    
    

    Reference: Adding a List

提交回复
热议问题