代码之家  ›  专栏  ›  技术社区  ›  sinan yılmaz

android.view.ViewRootImpl无法强制转换为android.view.view

  •  0
  • sinan yılmaz  · 技术社区  · 7 年前

    enter code here 我试图关闭弹出窗口时,触摸外部弹出窗口。我的vode工作API级别23+。但不工作API级别17。

    先谢谢你。 enter image description here

     LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
                            View popupView = layoutInflater.inflate(dosy.app.yds.R.layout.toast_popup, null);
                            final PopupWindow popupWindow = new PopupWindow(popupView,
                                    ActionBar.LayoutParams.MATCH_PARENT,
                                    ActionBar.LayoutParams.WRAP_CONTENT);
                            popupWindow.setOutsideTouchable(true);
                            popupWindow.setFocusable(true);
                            txtToast=(TextView)popupView.findViewById(dosy.app.yds.R.id.textViewToast);
                            txtToast.setText(mWord);
                            popupWindow.showAsDropDown(widget);
                            final   View parent = (View) popupWindow.getContentView().getParent();
                            //dim the window in the background
                            final WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
                            final  WindowManager.LayoutParams p = (WindowManager.LayoutParams) parent.getLayoutParams();
                            p.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
                            p.dimAmount = 0.2f;
                            wm.updateViewLayout(parent, p);
                            popupWindow.setTouchInterceptor(new View.OnTouchListener()
                            {
                                @Override
                                public boolean onTouch(View v, MotionEvent event) {
    
                                    if(event.getAction()==MotionEvent.ACTION_OUTSIDE){
                                        p.dimAmount = 0.0f;
                                        wm.updateViewLayout(parent, p);
                                        return true;
                                    }
                                    return false;
                                }
                            });
    
    0 回复  |  直到 7 年前