Android抛错:android.view.WindowManager$BadTokenException: Unable to add window -- token null is not

Android抛错:android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?

android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?

在使用PopupWindow时候出现该问题。

解决方案,在PopupWindow show的时候,用post包一层:

your_view?.post {
            PopupWindow.show(...)
        }

Android点击View显示PopupWindow,再次重复点击View关闭PopupWindow-CSDN博客文章浏览阅读5.6k次,点赞3次,收藏4次。Android点击View显示PopupWindow,再次重复点击View关闭PopupWindow这本身是一个看似很简单的问题,但是如果设置不当,就可能导致莫名其妙失效问题。通常在Android中使用PopupWindow是从某一个View中触发,为某一个View setOnClickListener,然后在View.OnClickListener中show出创建好的PopupWindow,https://blog.csdn.net/zhangphil/article/details/52587576Android Material Design:ListPopupWindow_listpopupwindow设置间距-CSDN博客文章浏览阅读7k次。Android Material Design:ListPopupWindowAndroid Material Design引入的ListPopupWindow,首先是一个PopupWindow,不过此PopupWindow内嵌一个List,给予此List设置一个Adapter,就相当Android为开发者做好了一个内置ListView的PopupWindows。如图所示:_listpopupwindow设置间距https://blog.csdn.net/zhangphil/article/details/48900349

Android PopupWindow-CSDN博客文章浏览阅读239次。代码:package zhangphil.test;import android.content.Context;import android.content.res.Resources;import android.graphics.Color;import android.os.Bundle;import android.support.annotation.Nullable...https://blog.csdn.net/zhangphil/article/details/82850102

猜你喜欢

转载自blog.csdn.net/zhangphil/article/details/134953273