项目中从popupWindow 跳转到一个有WebView(ScrollView)的新页面中。一滑动就crash。
查了一下。原来是android的bug (3.0之前)。
解决方法:在创建popupWindow不设置setFocusable(true).当要显示的时候再设置setFocusable(true). dimiss的时候设置为setFocusable(false)就可以了。
selectView = View.inflate(baseActivity, R.layout.select_pop_dialog, null);
selectPwindow = new PopupWindow(selectView, width, LayoutParams.WRAP_CONTENT);
// 设置允许在外点击消失
selectPwindow.setOutsideTouchable(true);
// 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景
selectPwindow.setBackgroundDrawable(new BitmapDrawable());
private void showSelectDialog() {
selectPwindow.showAtLocation(curMyView, Gravity.BOTTOM, 0, 0);
selectPwindow.setFocusable(true);
}
private void hideSelectDialog() {
if (null != selectPwindow && selectPwindow.isShowing())
{
selectPwindow.dismiss();
selectPwindow.setFocusable(false);
}
}