gpt4 book ai didi

android - PopupWindow TouchInterceptor 不工作

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:05:22 26 4
gpt4 key购买 nike

我正在尝试测试 PopupWindow 类。我创建了这个方法来显示弹出窗口:

    public void showPopup(){
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popup = new PopupWindow(popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
popup.setOutsideTouchable(true);
popup.setTouchable(true);
popup.setTouchInterceptor(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d("POPUP", event.toString());
if(event.getAction() == MotionEvent.ACTION_OUTSIDE){
popup.dismiss();
return true;
}
return true;
}
});
popup.showAtLocation(findViewById(R.id.main), Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 200);
}

弹出窗口显示正确,顺便说一句,触摸拦截器似乎根本不起作用:我没有收到任何日志信息,当然,如果在弹出窗口之外按下,弹出窗口也不会消失。

我是否必须在弹出窗口或承载它的 Activity 中设置一些其他属性?

最佳答案

 pw.setBackgroundDrawable (new BitmapDrawable());
pw.setFocusable(false);
pw.setOutsideTouchable(true);

使用此代码希望这对您有帮助

关于android - PopupWindow TouchInterceptor 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15570172/

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