使用PopupWindow的时候如果出现BadTokenException-unable to add window,token null is not valid错误。
错误的原因:
往往是因为window还没active的window;
解决的办法:
很简单,就是在onAttachedToWindow里面的时候再显示你的popupwindow,而不是在onCreate里面:
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
showPopupWindow();
}
本文介绍了解决在使用PopupWindow时遇到BadTokenException的具体原因及解决方案。错误通常发生在window尚未激活的情况下。解决方法是在onAttachedToWindow方法中显示PopupWindow,而非在onCreate方法中。
1万+

被折叠的 条评论
为什么被折叠?



