向 TextField Compose 光标位置添加填充

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

我想向 Textfield Composable 中的光标位置添加额外的 32 dp 填充,我尝试使用 TextFieldValue 并更新 TextRange 属性,但它不起作用。

 var textFieldValueState by remember {
        mutableStateOf(
            TextFieldValue(
                text = "hello",
                selection = TextRange(32.dp) 
            )
        )
    }
OutlinedTextField(
    value = textFieldValueState,
    onValueChange = { textFieldValueState = it },
    ...
    )
android android-jetpack-compose textfield
1个回答
0
投票

你应该在textstyle处使用textIndent,不仅对于第一行,而且对于接下来的段落你可以设置不同的填充,注意我们假设你想要制作32 dp的填充:

OutlinedTextField(
textStyle = TextStyle( 
textIndent = TextIndent(30.sp)))

也适用于其他线路:

    OutlinedTextField(
textStyle = TextStyle(
    textIndent = TextIndent(firstLine = 30.sp, restLine =32.sp)))
© www.soinside.com 2019 - 2024. All rights reserved.