我有一个活动ConstraintLayout
和它的片段:
<androidx.constraintlayout.widget.ConstraintLayout
...attributes....
>
<fragment
android:id="@+id/containerView"
app:navGraph="@navigation/some_navigation"
...other attributes...
/>
...other views...
我在活动代码中使用视图绑定:
binding = ActivityMainBinding.inflate(layoutInflater)
这里的问题是我无法访问binding.containerView
。
是否在以下情况下fragment
我应该使用findViewById
?
片段标签(<fragment>
) 不是一个view
它充当container
对于其他视图,因此您无法像其他视图一样访问它......
当您尝试使用访问非视图元素时,您将收到编译错误binding
相反,你可以使用,
supportFragmentManager.findFragmentById(R.id.containerView)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)