You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jetpack Compose AbstractComposeView弹出窗口显示为黑色的问题求助

Jetpack Compose AbstractComposeView弹出窗口显示为黑色的问题求助

大家好,我遇到了一个头疼的问题:我用AbstractComposeView创建了一个弹出视图,在Android Studio模拟器上打开时,这个弹出窗口的大部分区域都是黑色的。目前只有两个按钮是可见的,文本框虽然能选中,但窗口其余部分全黑,完全看不到正常的内容。

(原本配有两张场景截图,展示黑色的弹出窗口状态)

下面是我用来创建这个视图的代码:

class Swim_Set_Adder(
    composeView: View,
    private val Workout_Point: Workout
) : AbstractComposeView(composeView.context) {

    private val windowManager =
        composeView.context.getSystemService(Context.WINDOW_SERVICE)
                as WindowManager

    private var params: WindowManager.LayoutParams =
        WindowManager.LayoutParams().apply {
            type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL
            token = composeView.applicationWindowToken
            width = WindowManager.LayoutParams.WRAP_CONTENT
            height = WindowManager.LayoutParams.WRAP_CONTENT
            format = PixelFormat.OPAQUE
        }

    private var viewShowing = false

    init {
        ViewTreeLifecycleOwner.set(this, ViewTreeLifecycleOwner.get(composeView))
        ViewTreeViewModelStoreOwner.set(this, ViewTreeViewModelStoreOwner.get(composeView))
        setViewTreeSavedStateRegistryOwner(composeView.findViewTreeSavedStateRegistryOwner())
    }

    @ExperimentalComposeUiApi
    @Composable
    override fun Content() {
        Show()
    }

    fun show() {
        if (viewShowing) dismiss()
        windowManager.addView(this, params)
        viewShowing = true
    }

    fun dismiss() {
        if (!viewShowing) return
        disposeComposition()
        windowManager.removeViewImmediate(this)
        viewShowing = false
    }

    fun dispose() {
        dismiss()
        setViewTreeSavedStateRegistryOwner(null)
        ViewTreeLifecycleOwner.set(this, null)
        ViewTreeViewModelStoreOwner.set(this, null)
    }
}

我现在的目标是让这个弹出窗口能正常显示,让所有文本框都能被看到,有没有大佬能帮我分析下问题出在哪?

备注:内容来源于stack exchange,提问作者user21779968

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 15:52:58