小编Ami*_*mir的帖子

Android jetpack compose 中可组合的 TextField 的多样式文本编辑

我想更改TextFiled() 可组合项选定文本的文本样式( fontSize , color , fontWeight ,...) ,并使用 android jetpack compose中的按钮

(主要问题是,当我更改所选文本的文本样式时,TextField无法保存它,或者当我在 TextField 中添加/删除字母时,TextField会删除以前的文本样式。)

换句话说,当重组过程发生时,文本样式在 TextField() 中消失

在此输入图像描述

我的代码是:

@Composable
fun Show() {

    val inputText = remember{ mutableStateOf(TextFieldValue("This is a annotated text text"))}
    Column(
        modifier = Modifier.fillMaxSize().padding(5.dp) ,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        //=================== TextField
        CustomTextField(textInput = inputText)
        //==================== Button
        Button(onClick = {
            inputText.value = changeSegmentColor(inputText.value)

        }) {
            Text(text = "Change the text style of selected text")
        }
        //====================== …
Run Code Online (Sandbox Code Playgroud)

selectedtext textfield rich-text-editor textstyle android-jetpack-compose

5
推荐指数
1
解决办法
1819
查看次数