If you want to show it:
FrameLayout rootLayout = (FrameLayout)findViewById(android.R.id.content); View.inflate(this, R.layout.overlay_layout, rootLayout);
Then when you want to remove it:
FrameLayout rootLayout = (FrameLayout)findViewById(android.R.id.content); rootLayout.removeViewAt(rootLayout.getChildCount()-1);
This is a short solution, you must remove the View by specifying the RelativeLayout identifier in the XML file, and then delete: rootLayout.removeView(findViewById(R.id.the_id_of_the_relative_layout)); .
source share