Unable to add window -- token null is not valid; is your activity running?

版权声明:独学而无友,则孤陋寡闻。q群582951247 https://blog.csdn.net/mp624183768/article/details/82921285

 

您尝试过早显示popUpWindow,修复它,将Id作为主布局main_layout并使用下面的代码时会发生此错误

Java的:

        findViewById(R.id.main_layout).post(new Runnable() {
            public void run() {
                popupWindow.showAtLocation(findViewById(R.id.main_layout), Gravity.CENTER, 0, 0);
            }
        });

科特林: 

        main_layout.post {
            popupWindow?.showAtLocation(main_layout, Gravity.CENTER, 0, 0)
        }

 解决方法就是postDelay 1000加个延时

猜你喜欢

转载自blog.csdn.net/mp624183768/article/details/82921285