// get the root view of the current activity View rootView = getWindow().getDecorView().getRootView(); // set the background color of the root view rootView.setBackgroundColor(Color.WHITE);
// get the root view of an inflated layout View rootView = LayoutInflater.from(context).inflate(R.layout.my_layout, null).getRootView(); // add the root view to a parent ViewGroup ViewGroup parentView = findViewById(R.id.my_parent_view); parentView.addView(rootView);In this example, we're inflating a layout called `my_layout` using a `LayoutInflater`. Once we have the inflated view, we're getting its root view by calling `getRootView()`. Then, we're adding the root view to a parent `ViewGroup` called `my_parent_view`. Package Library: android.view, android.view.LayoutInflater