I know how to get the root view with View.getRootView(). I am also able to get the view from a button\'s onClick
event where the argument is a View. But how can
If your activity's view is declared in xml (ex activity_root.xml
), open the xml and assign an id to the root view:
android:id="@+id/root_activity"
Now in your class, import the view using:
import kotlinx.android.synthetic.main.activity_root.root_activity
You can now use root_activity
as the view.