不要使用PopupWindow默认构造方法
// declare view, width, height ... PopupWindow popupWindow = new PopupWindow(); popupWindow.setContentView(view); popupWindow.setWidth(width); popupWindow.setHeight(height);
上面这段代码在Android 4.0 真机(ZTE V889D)调试没有问题,但是在Android 2.2模拟器上使用,就会报运行时异常和空指针异常,改用下面的代码没有问题:
// declare view, width, height ... PopupWindow popupWindow = new PopupWindow(view, width, height);
所以,为了兼容性,不要使用PopupWindow默认构造方法。
欢迎转载,同时请注明出处