我想在我的应用程序中添加一个PopupMenu,但问题是它也应该在Android 2.3上工作。
我找到了一些帖子,人们建议使用AlertDialog作为替代方案,但我更喜欢PopupMenu ;)
我认为它应该在这个API级别中工作,因为我在几个应用程序中看到了它(我的手机有2.3.5版本,它可以正常工作)。
有没有可能让它起作用?
您必须在应用程序中导入与以下相同的支持v7: 添加具有资源的库
import android.support.v7.widget.PopupMenu;
使用该代码进行编译,然后您的弹出式菜单即兼容安卓2.2及以上版本。
PopupMenu可以在发送电子邮件的方法中尝试使用,您可以根据自己的需要填充xml。
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);
}
}
});