PopupWindow TouchInterceptor不工作 [英] PopupWindow TouchInterceptor not working
本文介绍了PopupWindow TouchInterceptor不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想测试PopupWindow类。我创建这个方法来显示弹出:
公共无效showPopup(){
LayoutInflater layoutInflater =(LayoutInflater)getBaseContext()getSystemService(LAYOUT_INFLATER_SERVICE)。
查看popupView = layoutInflater.inflate(R.layout.popup,NULL);
最后PopupWindow弹出=新PopupWindow(popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
popup.setOutsideTouchable(真);
popup.setTouchable(真);
popup.setTouchInterceptor(新OnTouchListener(){
@覆盖
公共布尔onTouch(视图V,MotionEvent事件){
Log.d(,弹出,event.toString());
如果(event.getAction()== MotionEvent.ACTION_OUTSIDE){
popup.dismiss();
返回true;
}
返回true;
}
});
popup.showAtLocation(findViewById(R.id.main),Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL,0,200);
}
弹出正确显示,顺便似乎触摸拦截器根本不工作:我没有得到任何的日志信息,当然弹出是不是如果pressing在它之外驳回。
有一些进一步的财产我都在弹出或在活动的主机它来设置?
解决方案
pw.setBackgroundDrawable(新BitmapDrawable());
pw.setFocusable(假);
pw.setOutsideTouchable(真);
使用code希望这是有益
I'm trying to test the PopupWindow class. I've created this method to show the popup:
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);
}
The popup is showing correctly,by the way it seems that the Touch Interceptor don't work at all: I don't get any log information and of course the popup is not dismissing if pressing outside of it.
Is there some further property I have to set in the popup or in the Activity which host it?
解决方案
pw.setBackgroundDrawable (new BitmapDrawable());
pw.setFocusable(false);
pw.setOutsideTouchable(true);
use this code hope this is helpful
这篇关于PopupWindow TouchInterceptor不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文