Jetpack Compose 上的模拟 Textview.append("text"))?

问题描述 投票:0回答:1

我希望当跟踪值发生变化时,将文本添加到前一个文本中,而不是完全重绘。

我查看了Basic Text和Text中的方法,但没有找到任何东西。 以前我可以使用 Textview.append("text")) 来实现此功能

kotlin android-jetpack-compose
1个回答
0
投票

你可以在jetpack中做这样的事情

@Composable
fun App() {
    var text by remember { mutableStateOf("Initial Text") }

    Column(modifier = Modifier.padding(5.dp)) {
        Text(text)
        Button(onClick = { text += " Append text" }) {
            Text("Append Text")
        }
    }
}

希望这有帮助

© www.soinside.com 2019 - 2024. All rights reserved.