我有一个ConstraintLayout
的活动,上面有片段:
<androidx.constraintlayout.widget.ConstraintLayout
...attributes....
>
<fragment
android:id="@+id/containerView"
app:navGraph="@navigation/some_navigation"
...other attributes...
/>
...other views...
我在活动代码中使用视图绑定:
binding = ActivityMainBinding.inflate(layoutInflater)
这里的问题是我无法访问CCD_ 2。如果是fragment
,我应该使用findViewById
吗?
Fragment标记(<fragment>
(不是view
,它充当其他视图的container
,因此您无法像访问其他视图一样访问它。。。
当您尝试使用binding
访问非视图元素时,会出现编译错误
相反,您可以使用
supportFragmentManager.findFragmentById(R.id.containerView)