gpt4 book ai didi

Android - 防止在 PopupWindow 之外单击按钮

转载 作者:搜寻专家 更新时间:2023-11-01 07:46:28 25 4
gpt4 key购买 nike

我花了一段时间试图让它工作,在网上寻找类似的解决方案,但似乎都没有用。我需要我的 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);
}
});
}
});
}

最佳答案

设置popupRAMS.setFocusable(false)。删除使弹出窗口消失所需的不必要的触摸。所以请替换

popupRAMS.setFocusable(true);

popupRAMS.setFocusable(false);

也尝试添加

popupRAMS.setOutsideTouchable(false);

希望对您有所帮助。

关于Android - 防止在 PopupWindow 之外单击按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43255773/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com