You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:Compose TextField设置Number键盘类型时onValueChange未触发

问题:设置数字键盘后OutlinedTextField的onValueChange不触发

当为OutlinedTextField设置keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),甚至用KeyboardOptions.Default.copy(keyboardType = KeyboardType.Number)指定数字键盘时,组件的onValueChange回调始终无法触发。

版本信息:

软件版本
Compose compiler1.4.6
Compose UI1.4.3
Kotlin1.8.2

复现代码:

import android.util.Log
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.OutlinedTextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.text.input.KeyboardType

@Composable
fun TestNumberInput() {
    var numbers by remember {
        mutableStateOf("")
    }

    OutlinedTextField(
        value = numbers, 
        onValueChange = { 
            Log.i("TEST", "numbers: $numbers")
            numbers = it
        }, 
        keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number)
    )
}

此前已见过类似问题,但引发原因和当前场景不匹配。

内容的提问来源于stack exchange,提问作者Damian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 13:52:20