I tried to change some part of the keyboard via imeAction,
but can still see that this only applies to the first textfield
enter image description here
How can I solve this problem?
@Composable
fun TipTimeLayout() {
EditNumberField(
label = R.string.bill_amount,
value = amountInput,
onValueChange = {amountInput = it},
keyboardOptions = KeyboardOptions.Default.copy(
keyboardType = KeyboardType.Number,
imeAction = ImeAction.Next
),
modifier = Modifier
.padding(bottom = 32.dp)
.fillMaxWidth()
)
)
EditNumberField(
value = tipInput,
keyboardOptions = KeyboardOptions.Default.copy(
keyboardType = KeyboardType.Number,
imeAction = ImeAction.Done
),
onValueChange = {tipInput = it},
label = R.string.how_was_the_service,
modifier = Modifier
.padding(top = 32.dp)
.fillMaxWidth()
)
}
}
/**
* Calculates the tip based on the user input and format the tip amount
* according to the local currency.
* Example would be "$10.00".
*/
private fun calculateTip(amount: Double, tipPercent: Double = 15.0): String {
val tip = tipPercent / 100 * amount
return NumberFormat.getCurrencyInstance().format(tip)
}
@Composable
fun EditNumberField(
value: String,
onValueChange: (String) -> Unit,
@StringRes label: Int,
keyboardOptions: KeyboardOptions,
modifier: Modifier = Modifier
) {
TextField(
value = value,
onValueChange = onValueChange,
modifier = Modifier,
label = { Text(stringResource(label))},
singleLine = true,
keyboardOptions = KeyboardOptions.Default.copy(
keyboardType = KeyboardType.Number,
imeAction = ImeAction.Next
)
)
}
When the user tabs the second text field, a Done button should appear in the lower right corner of the keyboard
New contributor
황서영 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.