【发布时间】:2019-07-09 18:45:52
【问题描述】:
我正在尝试打开一个带有 4 个按钮的弹出窗口,当按下按钮或用户在弹出窗口之外单击时,该窗口将关闭。我会做一个警告对话,但这只会支持 3 个按钮。
关于同一件事有很多问题,我找不到任何一致的答案或任何适合我的答案(包括已弃用的 Bitmap Drawable)。我已将我看到的所有建议都放入我的代码中,但无济于事。
这是我目前使用过的所有东西:
//to create new popup window
LayoutInflater chooseMealInflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View chooseMealLayout = chooseMealInflater.inflate(R.layout.choose_meal_dialog, null);
PopupWindow chooseMealPopup = new PopupWindow(chooseMealLayout, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
//to make popup dismiss on touch outside
chooseMealPopup.setOutsideTouchable(true);
chooseMealPopup.setFocusable(true);
chooseMealPopup.setContentView(chooseMealLayout);
chooseMealPopup.showAtLocation (chooseMealLayout, Gravity.CENTER,0,0);
chooseMealPopup.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
我试图找到所有我能找到的东西,比如将setFocusable 保留在showAtLocation 之前,但是当我运行应用程序时,单击时没有任何反应。认为这可能与我的代码有关,因为我是新手,并不真正知道自己在做什么。
【问题讨论】:
标签: java android-studio popup popupwindow