本文介绍了有没有一种方法来检查android WindowManager是否已经包含一个视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试执行WindowManager.removeView()时,

When I try to do a WindowManager.removeView(),

E/AndroidRuntime( 2445): java.lang.IllegalArgumentException: View=android.widget.LinearLayout{41a03700 V.E..... ......I. 0,0-0,0} not attached to window manager

E/AndroidRuntime( 2445):             at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:370)

E/AndroidRuntime( 2445):             at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:299)

E/AndroidRuntime( 2445):             at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:79)

我收到此致命错误,因为视图不在窗口管理器中.有没有办法检查windowmanager之前是否已经添加过视图?我在

I get this fatal error because the view was not in the window manager.Is there no way to check if windowmanager had already added the view before?I do not see any such method in the source

推荐答案

您可以检查视图的窗口标记是否为空:

You can check to see if the view's window token is null:

if(view.getWindowToken() != null){
    WindowManager.removeView(view);
}

您也可以捕获异常:

try{
    WindowManager.removeView(view);
}catch(IllegalArgumentException e){
    Log.e(debug_tag, "view not found");
}

这篇关于有没有一种方法来检查android WindowManager是否已经包含一个视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 18:18