gpt4 book ai didi

android - java.lang.IllegalStateException : ViewTreeLifecycleOwner not found from androidx. constraintlayout.widget.ConstraintLayout

转载 作者:行者123 更新时间:2023-12-04 11:43:38 35 4
gpt4 key购买 nike

当我尝试使用 XML 在覆盖中插入 Compose(在其他应用程序上绘制)时,我得到了这个异常:

java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from androidx.constraintlayout.widget.ConstraintLayout{d596746 V.E...... ......ID 0,0-0,0}
但是没有覆盖(在 Activity 中)它可以正常工作。有谁知道如何解决?我已经将 AppCompat 库更新到 1.3.0
我的 XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black">
<androidx.compose.ui.platform.ComposeView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/compose_view"/>
</androidx.constraintlayout.widget.ConstraintLayout>
我的叠加代码:
mParams = WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT
)
layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
mView = layoutInflater.inflate(R.layout.power_overlay, null)
mParams!!.gravity = Gravity.CENTER
mWindowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
mWindowManager.addView(mView, mParams)

最佳答案

对我来说,这是因为我没有包含 appcompat 库,并且我的 Activity 继承自 Activity 而不是 AppCompatActivity。通过添加库解决了问题:

implementation("androidx.appcompat:appcompat:1.3.1")
并从 AppCompatActivity 继承:
class MyActivity: AppCompatActivity() {
...
}

关于android - java.lang.IllegalStateException : ViewTreeLifecycleOwner not found from androidx. constraintlayout.widget.ConstraintLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68395975/

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