我是新来的编写,我有一个问题,输入文本字段的磨损操作系统。问题是,我不能让软键盘的工作,因为它通常在Android上。而且,当我试图实现相同的布局在XML中-它的工作。所以,当我点击输入文本字段的键盘弹出,然后隐藏。当我再次点击-键盘弹出,并保持打开。但如果我尝试输入任何文本-什么都没有出现在输入字段(在键盘本身),虽然输入的文本是传递到输入文本字段的UI。
下面是我在模拟器上的日志,当我点击输入文本字段打开键盘:
2021-11-24 09:44:36.569 W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
2021-11-24 09:44:36.571 W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection
2021-11-24 09:44:36.649 W/RecordingIC: requestCursorUpdates is not supported
以下是我在真实的设备上得到的结果:
2021-11-24 09:35:39.783 W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
2021-11-24 09:35:39.872 W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
2021-11-24 09:35:39.873 W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
2021-11-24 09:35:39.873 W/IInputConnectionWrapper: setComposingRegion on inactive InputConnection
2021-11-24 09:35:39.873 W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
2021-11-24 09:35:39.873 W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
2021-11-24 09:35:39.873 W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
2021-11-24 09:35:39.873 W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
2021-11-24 09:35:39.873 W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
2021-11-24 09:35:39.882 W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
2021-11-24 09:35:39.883 W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
2021-11-24 09:35:39.884 W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection
2021-11-24 09:35:39.888 W/IInputConnectionWrapper: getSelectedText on inactive InputConnection
2021-11-24 09:35:39.890 W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
2021-11-24 09:35:39.891 W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
2021-11-24 09:35:39.891 W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
2021-11-24 09:35:39.891 W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
2021-11-24 09:35:39.891 W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
下面是我的“组合”:
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun ActivationScreen() {
var key by remember { mutableStateOf("") }
var isReady by remember {
mutableStateOf(false)
}
Column(modifier = Modifier
.padding(40.dp)
.fillMaxSize()
) {
val keyboardController = LocalSoftwareKeyboardController.current
val focusRequester = FocusRequester()
BasicTextField(
value = key,
onValueChange = {
//isReady = it.length>11
key = it
},
singleLine = true,
keyboardOptions = KeyboardOptions.Default.copy(
imeAction = ImeAction.Done
),
keyboardActions = KeyboardActions(
onDone = {
keyboardController?.hide()
}
),
modifier = Modifier
.size(140.dp, 20.dp)
.background(Color.White)
.align(Alignment.CenterHorizontally)
//.focusRequester(focusRequester)
//.focusOrder(focusRequester)
)
Text(
text = "ACTIVATION",
)
val status = if (isReady) "READY" else "NOT READY"
Text(
text = status,
)
}
}
2条答案
按热度按时间jk9hmnmh1#
You should avoid text input on Wear, but if you do really need it, the GBoard activity is the best way to activate.
See https://developer.android.com/reference/androidx/wear/input/RemoteInputIntentHelper.Companion#createActionRemoteInputIntent()
Note: As @TiagoPeresFrança mentioned in the comments:
In order to use
wearableExtender
, you must be on version 1.2.0+ of the wear-input dependency. As of today, version 1.2.0-alpha02 should be used. In your app gradle file, make sure you have as dependencyimplementation 'androidx.wear:wear-input:1.2.0-alpha02'
.kse8i1jr2#
根据@ YuriSchimke的回答,这里有一个通用组件实现,它接受占位符、值和onChange作为属性。
注意:这需要androidx.磨损:磨损输入:1.2.0+