当前位置:网站首页>Kotlin Compose 监听软键盘 点击enter提交事件
Kotlin Compose 监听软键盘 点击enter提交事件
2022-06-25 04:01:00 【安果移不动】
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun TodoInputText(
text: String,
onTextChanged: (String) -> Unit,
onImeAction: () -> Unit,
modifier: Modifier = Modifier,
) {
val keyboardController = LocalSoftwareKeyboardController.current
TextField(
value = text,
onValueChange = onTextChanged,
modifier = modifier,
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.Transparent),
maxLines = 1,
//配置软键盘
keyboardOptions = KeyboardOptions.Default.copy(imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(onDone = {
onImeAction()
//点击完成之后 隐藏键盘
keyboardController?.hide()
})
)
}

使用这个controller
LocalSoftwareKeyboardController
单是这个和Flutter不同。不用设置到实际的控件当中
onImeAction: () -> Unit, 就是输入完成点击回车要做的事情。
非常的人性化。
边栏推荐
- 2.0springmvc uses restful
- 515. find the maximum value / Sword finger offer II 095 in each tree row Longest common subsequence
- Record of the 25th week
- JS' sort() function
- js的arguments
- 为什么TCP握手刚刚好是3次呢?
- Synchronous and asynchronous functions (callback function, promise, generator, async/await)
- ROS2/DDS/QoS/主题的记录
- GBASE 8s的包
- jsz中的join()
猜你喜欢

哪个编程语言实现hello world最烦琐?

The solution of wechat applet switchtab unable to take parameters

UCLA | generative pre training for black box optimization

English Grammar - pronunciation rules

cnpm : 无法加载文件 C:\Users\Administrator\AppData\Roaming\npm\cnpm.ps1,因为在此系统上禁止运行脚本。

重磅直播 | 相移法+多频外差之数学原理推导+实现

CTF_ Web:php weak type bypass and MD5 collision

Musk released humanoid robot. Why is AI significant to musk?

Unity Quad culls shaders with back faces and transparent parts

Office macro virus bounce shell experiment
随机推荐
js的arguments
JS' sort() function
JS arguments
GBASE 8s存儲過程語法結構
CTF_ Web: Advanced questions of attack and defense world expert zone WP (1-4)
cnpm : 无法加载文件 C:\Users\Administrator\AppData\Roaming\npm\cnpm.ps1,因为在此系统上禁止运行脚本。
Multithreading structure of gbase 8s
Gbase 8s overall architecture
GBASE 8s 索引R树
2.0springmvc uses restful
论文笔记: 多标签学习 ESMC (没看懂, 还没写出来, 暂时放这里占个位置)
[untitled]
坐标系左乘右乘
我的IC之旅——资深芯片设计验证工程师成长——“胡”说IC工程师完美进阶
Retrofit 源码分析
彻底理解数据库事务
关于TCP连接四次握手(或者叫四次挥手)的详细总结
CTF_ Web: Advanced questions of attack and defense world expert zone WP (19-21)
Classification of gbase 8s locks
halcon之区域:多种区域(Region)生成(3)