← Back to Foundation
BaseTextField
Component
in
Foundation
. Since 0.1.0-dev16Overview
Examples
Community Notes
Composable that enables users to edit text via hardware or software keyboard.
Whenever the user edits the text, onValueChange is called with the most up to date state represented by TextFieldValue. TextFieldValue contains the text entered by user, as well as selection, cursor and text composition information. Please check TextFieldValue for the description of its contents.
It is crucial that the value provided in the onValueChange is fed back into BaseTextField in order to have the final state of the text being displayed.
Overloads
BaseTextField
@Deprecated(
"Use BasicTextField instead.",
replaceWith = ReplaceWith(
"BasicTextField(value, onValueChange, modifier, textStyle.merge(TextStyle(color = " +
"textColor)), keyboardType, imeAction, onImeActionPerformed, visualTransformation, " +
"onTextLayout, onTextInputStarted, cursorColor)",
"androidx.compose.foundation.text.BasicTextField",
"androidx.compose.foundation.AmbientContentColor",
"androidx.compose.foundation.AmbientTextStyle",
"androidx.compose.ui.text.TextStyle",
)
)
@Composable
@ExperimentalFoundationApi
fun BaseTextField(
value: TextFieldValue,
onValueChange: (TextFieldValue) -> Unit,
modifier: Modifier = Modifier,
textColor: Color = Color.Unspecified,
textStyle: TextStyle = TextStyle(),
keyboardType: KeyboardType = KeyboardType.Text,
imeAction: ImeAction = ImeAction.Default,
onImeActionPerformed: (ImeAction) -> Unit = {},
visualTransformation: VisualTransformation = VisualTransformation.None,
onTextLayout: (TextLayoutResult) -> Unit = {},
onTextInputStarted: (SoftwareKeyboardController) -> Unit = {},
cursorColor: Color = AmbientContentColor.current
)
Parameters
Name | Description |
---|---|
value | The TextFieldValue to be shown in the BaseTextField. |
onValueChange | Called when the input service updates values in TextFieldValue. |
modifier | optional Modifier for this text field. |
textColor | Color to apply to the text. If Color.Unspecified, and textStyle has no color set, this will be AmbientContentColor. |
textStyle | Style configuration that applies at character level such as color, font etc. The default textStyle uses the AmbientTextStyle defined by the theme |
keyboardType | The keyboard type to be used in this text field. Note that this input type is honored by IME and shows corresponding keyboard but this is not guaranteed. For example, some IME may send non-ASCII character even if you set KeyboardType.Ascii. |
imeAction | The IME action. This IME action is honored by IME and may show specific icons on the keyboard. For example, search icon may be shown if ImeAction.Search is specified. Then, when user tap that key, the onImeActionPerformed callback is called with specified ImeAction. |
onImeActionPerformed | Called when the input service requested an IME action. When the input service emitted an IME action, this callback is called with the emitted IME action. Note that this IME action may be different from what you specified in imeAction. |
visualTransformation | The visual transformation filter for changing the visual representation of the input. By default no visual transformation is applied. |
onTextLayout | Callback that is executed when a new text layout is calculated. |
onTextInputStarted | Callback that is executed when the initialization has done for communicating with platform text input service, e.g. software keyboard on Android. Called with SoftwareKeyboardController instance which can be used for requesting input show/hide software keyboard. |
cursorColor | Color of the cursor. If Color.Unspecified, there will be no cursor drawn @see TextFieldValue @see ImeAction @see KeyboardType @see VisualTransformatio |
Next ComponentBasicSecureTextField →