Unable to add window -- token android.view.ViewRootImpl$W@e3124a is not vali

环境:
在PopopWindow里面使用Spinner组件,会报错如下:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.sg.huosansihu, PID: 30027
    android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@e3124a is not valid; is your activity running?
        at android.view.ViewRootImpl.setView(ViewRootImpl.java:709)
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:319)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
        at android.widget.PopupWindow.invokePopup(PopupWindow.java:1272)
        at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:1119)
        at android.widget.ListPopupWindow.show(ListPopupWindow.java:663)
        at android.widget.Spinner$DropdownPopup.show(Spinner.java:1236)
        at android.widget.Spinner.performClick(Spinner.java:765)
        at androidx.appcompat.widget.AppCompatSpinner.performClick(AppCompatSpinner.java:443)
        at android.view.View$PerformClick.run(View.java:21559)
        at android.os.Handler.handleCallback(Handler.java:815)
        at android.os.Handler.dispatchMessage(Handler.java:104)
        at android.os.Looper.loop(Looper.java:207)
        at android.app.ActivityThread.main(ActivityThread.java:5845)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:768)

解决方法:
在Spinner组件XML属性里面添加如下内容:

android:spinnerMode="dialog"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值