【发布时间】:2023-01-30 16:00:27
【问题描述】:
使用 AbstractComposeView 固有的 Compose 视图 在片段的 XML ui 代码中 知道这个片段是导航图的一部分(Jetpack 导航) 当我按下后退按钮回到我的片段时,撰写视图只是消失了. 这只是我第一次打开片段时画的。
波纹管查看代码
class ProgressComposeView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : AbstractComposeView(context, attrs, defStyleAttr) {
private var steps = mutableStateOf(0)
private var currentStep: Int = 0
private var windowWidth: Int = 0
@Composable
override fun Content() {
ProgressView(steps.value, currentStep, windowWidth)
}
fun setData(steps: Int, currentStep: Int, windowWidth: Int) {
this.steps.value = steps
this.currentStep = currentStep
this.windowWidth = windowWidth
}
}
@Composable
fun ProgressView(totalSteps: Int, currentStep: Int, windowWidth: Int) {
..... }
【问题讨论】:
-
你能提供片段的代码吗?也许你需要在
onViewCreated方法中调用setContent。 -
有同样的问题,setContent{} 代码块放在 onViewCreated 方法中 - 它没有帮助
-
@Rob 我回答了这个问题,请检查我的回答
标签: android android-fragments android-jetpack-compose