Get root view from current activity

后端 未结 12 2041
不知归路
不知归路 2020-11-22 09:18

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

12条回答
  •  执笔经年
    2020-11-22 10:02

    For those of you who are using the Data Binding Library, to get the root of the current activity, simply use:

    View rootView = dataBinding.getRoot();
    

    And for Kotlin users, it's even simpler:

    val rootView = dataBinding.root
    

提交回复
热议问题