gpt4 book ai didi

android - 开个弹窗让外人照样可以摸

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:23:05 25 4
gpt4 key购买 nike

如何在 Android 上打开 PopupWindow 并在不关闭 PopupWindow 的情况下让所有其他组件可触摸?

它是这样创建的:

public class DynamicPopup {
private final PopupWindow window;
private final RectF rect;
private final View parent;
private final RichPageView view;

public DynamicPopup(Context context, RichPage page, RectF rectF, View parent) {
this.parent = parent;
rect = rectF;

window = new PopupWindow(context);

window.setBackgroundDrawable(new BitmapDrawable());
window.setWidth((int) rect.width());
window.setHeight((int) rect.height());
window.setTouchable(true);
window.setFocusable(true);
window.setOutsideTouchable(true);

view = new RichPageView(context, page, false);
window.setContentView(view);

view.setOnCloseListener(new Listener(){
@Override
public void onAction() {
window.dismiss();
}
});


}

public void show() {
window.showAtLocation(parent, Gravity.NO_GRAVITY, (int) rect.left, (int) rect.top);
}
}

最佳答案

就像 ernazm 说的那样

As per javadocs

Controls whether the pop-up will be informed of touch events outside of its window. This only makes sense for pop-ups that are touchable but not focusable

正在努力

window.setTouchable(true);
window.setFocusable(false);
window.setOutsideTouchable(false);

当窗口touchalbe为true,focusable为false时,setOutsideTouchable()有效,如果setOutsideTouchable(true),弹出窗口外的触摸将被关闭,否则弹出窗口外仍然可以触摸而不关闭。

关于android - 开个弹窗让外人照样可以摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7271784/

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