[英]Android: Using PopupMenu in API level 9
我想在我的應用程序中添加一個PopupMenu。 問題是它也適用於Android 2.3。 我發現一些帖子,人們建議使用AlertDialog作為替代,但我更喜歡PopupMenu;)
我認為它應該在這個API級別工作,因為我已經在幾個應用程序中看到它(我的手機有2.3.5並且它工作正常)。
有沒有可能使這項工作?
您必須在應用程序中導入支持v7,如下所示: 使用資源添加庫
import android.support.v7.widget.PopupMenu;
編譯你的代碼,然后你的彈出菜單兼容Android 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);
}
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.