我花了一段时间试图让这个工作,在网上寻找类似的解决方案,但似乎没有工作。我需要我的PopupWindow只在点击生成按钮时被解雇,而不是通过在窗口外单击。任何人都遇到过这个问题?Android - 防止按钮点击PopupWindow以外
private void LoadRAMSPopup() {
mainLayout.getForeground().setAlpha(150);
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final View ramsView = layoutInflater.inflate(R.layout.popup_rams, null);
final PopupWindow popupRAMS = new PopupWindow(
ramsView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
);
if (Build.VERSION.SDK_INT >= 21) {
popupRAMS.setElevation(5.0f);
}
findViewById(R.id.mainLayout).post(new Runnable() {
@Override
public void run() {
popupRAMS.showAtLocation(findViewById(R.id.mainLayout), Gravity.CENTER, 0, 0);
popupRAMS.setOutsideTouchable(false);
popupRAMS.setFocusable(true);
popupRAMS.update();
Button btnGenerate = (Button) ramsView.findViewById(R.id.btnGenerate);
btnGenerate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), CreateRAMSActivity.class);
startActivity(intent);
popupRAMS.dismiss();
mainLayout.getForeground().setAlpha(0);
}
});
}
});
}
此作品在一定程度上,因为它不允许弹出窗口上点击外面被解雇,但我还需要防止一切在可点击的下方的视图中,弹出窗口位于顶部。 – James
在这种情况下,我不认为你的流行音乐会奏效。你必须用一个布局文件来管理这个。 –
这将如何实现?从来没有这样做... – James