Getting root view of Activity in Android

Android root view

Sometimes we need to get root view of Android Activity. There are different approaches on how to do it.

Approach 1 — specify view id

Just specify view id of the root view in your layout:


And then find it in your code:

val rootView = findViewById(

Approach 2 — use

Just get the root view using android R class:

val rootView = findViewById(

, ,

Leave a Reply

Your email address will not be published. Required fields are marked *