1

I used

 ((WindowManager) context.getSystemService(Service.WINDOW_SERVICE)).removeView(view);

but it didn't work..view is still showing on the screen. so how to remove WindowManager view from screen?

i Created it like this

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);
}
Shehan Ekanayake
  • 1,581
  • 4
  • 20
  • 35

1 Answers1

-2
windowManager.removeViewImmediate(view);

Make sure you added that view before or it will crash your app

Johnny Lynch
  • 7
  • 1
  • 5