Android 4.1+ PopupWindow最简单的例子

时间:2015-03-17 09:40:59

标签: java android android-actionbar android-view android-menu

我想要PopupWindow的简单明了的例子(简单如popupMenu) 我想用popupWindow替换popupMenu 请帮忙。

1 个答案:

答案 0 :(得分:1)

我解决了这个问题:

LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
PopupWindow popup = new PopupWindow(
    inflater.inflate(R.layout.popup_window, null, false),
    WindowManager.LayoutParams.WRAP_CONTENT,
    WindowManager.LayoutParams.WRAP_CONTENT,
    true
);
popup.showAtLocation(
    findViewById(R.id.main),
    Gravity.END | Gravity.TOP,
    dpToPx(16),
    dpToPx(42)
);