gpt4 book ai didi

android - Jetpack 撰写 : ViewTreeLifecycleOwner not found

转载 作者:行者123 更新时间:2023-12-04 23:43:44 34 4
gpt4 key购买 nike

在我的 fragment 中使用 Compose 时出现此错误,在 XML 的情况下可以正常工作ViewTreeLifecycleOwner not found from androidx.fragment.app.FragmentContainerView我正在使用单一 Activity 方法 没有 使用 Jetpack 导航组件
Activity :

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_nav)
supportFragmentManager.commit {
setReorderingAllowed(true)
add<InboxFragment>(R.id.nav_fragmentContainerView_appNav)
}
}
<androidx.fragment.app.FragmentContainerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nav_fragmentContainerView_appNav"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
分段:
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return ComposeView(requireContext()).apply {
setContent {
Text(text = "HELLO FRIEND!")
}
}
}
依赖项:
def fragment_version = "1.3.3"
implementation("androidx.fragment:fragment-ktx:$fragment_version")

def compose_version = "1.0.0-beta06"
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.activity:activity-compose:1.3.0-alpha07"
classpath "com.android.tools.build:gradle:7.0.0-alpha15"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.30"

最佳答案

由于您使用的是 AppCompatActivity , 只有 appcompat 1.3版本填充ViewTreeLifecycleOwner .
添加:

implementation 'androidx.appcompat:appcompat:1.3.0'

关于android - Jetpack 撰写 : ViewTreeLifecycleOwner not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67586282/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com