步骤一。定义键盘操作对象
val requester = remember {//用于请求焦点的对象
FocusRequester()
}
val keyboard = LocalSoftwareKeyboardController.current//用于操作键盘的对象
步骤2 针对textFiled 来进行添加Modify 属性 focusRequester
BasicTextField(value = input,
onValueChange = { value ->
onInput(value);
},
modifier = Modifier
.focusRequester(requester)
步骤3 请求焦点并弹出键盘
LaunchedEffect(key1 = Unit, block = {
requester.requestFocus()//首次进入和重组页面请求焦点
keyboard?.show()//首次进入页面弹出键盘,注意必须先获取焦点才能弹出键盘成功
})