通过将BasicTextField的onFocusChanged()回调函数中的scroll状态设置为false来阻止该行为。以下是设置的示例代码:
var textFieldValue by remember { mutableStateOf("") }
BasicTextField(
value = textFieldValue,
onValueChange = { textFieldValue = it },
modifier = Modifier
.fillMaxWidth()
.height(100.dp)
.border(1.dp, Color.Black)
.padding(4.dp),
onFocusChanged = { focusState ->
if (focusState.isFocused) {
// 防止 BasicTextField 自动滚动到顶部
scroll(state, 0)
// 停止滚动
state.scroll = false
} else {
// 恢复滚动
state.scroll = true
}
}
)