android.view.ViewRootImpl无法转换为android.view.View

时间:2018-11-10 12:04:55

标签: android api view classcastexception rootview

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 个答案:

没有答案