我用过
((WindowManager) context.getSystemService(Service.WINDOW_SERVICE)).removeView(view);
但它没有工作......视频仍在屏幕上显示。 那么如何从屏幕中删除WindowManager视图?
我像这样创建了
public void create()
{
windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
layoutParams = new WindowManager.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT |
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSPARENT);
int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,10, context.getResources().getDisplayMetrics());
layoutParams.x = 265;
layoutParams.y = height;
layoutParams.format = PixelFormat.TRANSLUCENT;
LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.ad_dialog, null);
Button bttnOk = (Button) view.findViewById(R.id.bttn_ok);
Button bttnCancel =(Button) view.findViewById(R.id.bttn_cancel);
bttnOk.setOnClickListener(this);
bttnCancel.setOnClickListener(this);
windowManager.addView(view, layoutParams);
}
答案 0 :(得分:-1)
c()
确保您之前添加了该视图,否则会导致应用崩溃