我正在关注一个Android开发者Codelab.我将此代码片段转换为可组合的:
OutlinedTextField(
value = userGuess,
singleLine = true,
shape = shapes.large,
modifier = Modifier.fillMaxWidth(),
colors = TextFieldDefaults.colors(
focusedContainerColor = colorScheme.surface,
unfocusedContainerColor = colorScheme.surface,
disabledContainerColor = colorScheme.surface,
),
onValueChange = onUserGuessChanged ,
label = { Text(stringResource(R.string.enter_your_word)) },
isError = false,
keyboardOptions = KeyboardOptions.Default.copy(
imeAction = ImeAction.Done
),
keyboardActions = KeyboardActions(
onDone = { onKeyboardDone() }
)
)
OnUserGuessChanged和onKeyBoardDone都是lambdas.这是Composable函数的头
@Composable
fun myComposableFunction(
onUserGuessChanged: (String) -> Unit,
onKeyboardDone: () -> Unit,
modifier: Modifier = Modifier
) {
[...]
为什么onValueChanged必须不带大括号和函数括号赋值,而onDone必须同时赋值??它们之间有什么特点或区别?