【发布时间】:2014-03-26 22:38:42
【问题描述】:
我正在尝试在按下某个菜单项时创建一个弹出窗口。我想我有大部分代码,但是我不确定要为 showAtLocation(...) 或 showAsDropDown(...) 做什么。
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
...
case R.id.about:
displayPopupWindow();
return true;
...
}
}
public void displayPopupWindow() {
PopupWindow popup = new PopupWindow(this);
View layout = getLayoutInflater().inflate(R.layout.popup, null);
popup.setContentView(layout);
popup.setOutsideTouchable(true);
popup.setFocusable(true);
popup.showAtLocation(??, Gravity.CENTER, 0, 0);
}
我应该为菜单的视图添加什么,或者我应该以其他方式执行此操作?我希望这是有道理的,感谢您的帮助!
【问题讨论】:
-
这篇文章可能会对 showAtLocation 部分有所启发:stackoverflow.com/questions/7926689/…
标签: android menu menuitem popupmenu android-popupwindow