Android: using PopupMenu in level 9 API

I like to add PopupMenu to my application. The problem is that it should work on Android 2.3 as well. I found several posts in which people suggest using AlertDialog as an alternative, but I prefer PopupMenu;)

I think it should work at this level of the API because I have seen it in several applications (my phone has 2.3.5 and it works fine).

Is there any way to do this work?

+5
source share
2 answers

PopupMenu maybe you can try this in the email sending method and you can inflate your xml according to your own needs:

    LayoutInflater inflater = (LayoutInflater)EEActionListDetail.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    Display display = getWindowManager().getDefaultDisplay();

    int width = display.getWidth()/2;
    int height = display.getHeight()/2;

    View pop = inflater.inflate(R.layout.popupemail,null,false);
    pop.measure(View.MeasureSpec.UNSPECIFIED,View.MeasureSpec.UNSPECIFIED);
    height = pop.getMeasuredHeight();
    width = pop.getMeasuredWidth()+200;
    pu = new PopupWindow(pop,width,height,true);
    pu.showAtLocation(findViewById(R.id.ll3),Gravity.CENTER,1,1);

    Button brnSend = (Button)pu.getContentView().findViewById(R.id.btnSend);
    Button close = (Button)pu.getContentView().findViewById(R.id.close);

    Subject = (EditText)pu.getContentView().findViewById(R.id.subject);
    Message = (EditText)pu.getContentView().findViewById(R.id.message);

    close.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            pu.dismiss();

        }
    });
    brnSend.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            for(int j=0;j<EmailArray.size();j++){
                String EmailSent = EmailArray.get(j);
                SendEmailALL(EmailSent);
            }
        }
    });
+3
source
  • v7 , :

  • import android.support.v7.widget.PopupMenu;

  • , Android 2.2 .

+13

All Articles