我有一个PopUpWindow需要在Activity启动时加载,它使用屏幕的DisplayMetrics以及其他东西。但是,我收到错误“无法添加窗口 - 令牌null无效;您的活动是否正在运行?”对于welcome.showAtLocation(popupview2, Gravity.CENTER, 0, 0);
行。
如何仅在检索到资源后才能显示PopUpWindow?
我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LayoutInflater inflater = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
dpWidth = displayMetrics.widthPixels / displayMetrics.density;
dpHeight = displayMetrics.heightPixels / displayMetrics.density;
popupview2 = inflater.inflate(R.layout.start_layout, null);
welcome = new PopupWindow(popupview2, (int) dpWidth, (int) dpHeight);
welcome.setAnimationStyle(R.style.Animation2);
welcome.showAtLocation(popupview2, Gravity.CENTER, 0, 0);
}
所有帮助表示赞赏。