TextField
Material Design filled text field.
Text fields allow users to enter text into a UI. They typically appear in forms and dialogs. Filled text fields have more visual emphasis than outlined text fields, making them stand out when surrounded by other content and components.
If you are looking for an outlined version, see OutlinedTextField.
A simple single line text field looks like:
Parameters
the input text to be shown in the text field
the callback that is triggered when the input service updates the text. An updated text comes as a parameter of the callback
the Modifier to be applied to this text field
controls the enabled state of this text field. When false
, this component will not respond to user input, and it will appear visually disabled and disabled to accessibility services.
controls the editable state of the text field. When true
, the text field cannot be modified. However, a user can focus it and copy text from it. Read-only text fields are usually used to display pre-filled forms that a user cannot edit.
the style to be applied to the input text. Defaults to LocalTextStyle.
the optional label to be displayed inside the text field container. The default text style for internal Text is Typography.bodySmall when the text field is in focus and Typography.bodyLarge when the text field is not in focus
the optional placeholder to be displayed when the text field is in focus and the input text is empty. The default text style for internal Text is Typography.bodyLarge
the optional leading icon to be displayed at the beginning of the text field container
the optional trailing icon to be displayed at the end of the text field container
the optional prefix to be displayed before the input text in the text field
the optional suffix to be displayed after the input text in the text field
the optional supporting text to be displayed below the text field
indicates if the text field's current value is in error. If set to true, the label, bottom indicator and trailing icon by default will be displayed in error color
transforms the visual representation of the input value For example, you can use PasswordVisualTransformation to create a password text field. By default, no visual transformation is applied.
software keyboard options that contains configuration such as KeyboardType and ImeAction.
when the input service emits an IME action, the corresponding callback is called. Note that this IME action may be different from what you specified in KeyboardOptions.imeAction.
when true
, this text field becomes a single horizontally scrolling text field instead of wrapping onto multiple lines. The keyboard will be informed to not show the return key as the ImeAction. Note that maxLines parameter will be ignored as the maxLines attribute will be automatically set to 1.
the maximum height in terms of maximum number of visible lines. It is required that 1 <= minLines<= maxLines. This parameter is ignored when singleLine is true.
the minimum height in terms of minimum number of visible lines. It is required that 1 <= minLines<= maxLines. This parameter is ignored when singleLine is true.
an optional hoisted MutableInteractionSource for observing and emitting Interactions for this text field. You can use this to change the text field's appearance or preview the text field in different states. Note that if null
is provided, interactions will still happen internally.
defines the shape of this text field's container
TextFieldColors that will be used to resolve the colors used for this text field in different states. See TextFieldDefaults.colors.
Samples
androidx.compose.material3.samples.SimpleTextFieldSampleandroidx.compose.material3.samples.TextFieldWithPlaceholderandroidx.compose.material3.samples.TextFieldWithIconsandroidx.compose.material3.samples.TextFieldWithPrefixAndSuffixandroidx.compose.material3.samples.TextFieldWithErrorStateandroidx.compose.material3.samples.TextFieldWithSupportingTextandroidx.compose.material3.samples.PasswordTextFieldandroidx.compose.material3.samples.TextFieldWithHideKeyboardOnImeActionMaterial Design filled text field.
Text fields allow users to enter text into a UI. They typically appear in forms and dialogs. Filled text fields have more visual emphasis than outlined text fields, making them stand out when surrounded by other content and components.
If you are looking for an outlined version, see OutlinedTextField.
See example usage:
Parameters
the input TextFieldValue to be shown in the text field
the callback that is triggered when the input service updates values in TextFieldValue. An updated TextFieldValue comes as a parameter of the callback
the Modifier to be applied to this text field
controls the enabled state of this text field. When false
, this component will not respond to user input, and it will appear visually disabled and disabled to accessibility services.
controls the editable state of the text field. When true
, the text field cannot be modified. However, a user can focus it and copy text from it. Read-only text fields are usually used to display pre-filled forms that a user cannot edit.
the style to be applied to the input text. Defaults to LocalTextStyle.
the optional label to be displayed inside the text field container. The default text style for internal Text is Typography.bodySmall when the text field is in focus and Typography.bodyLarge when the text field is not in focus
the optional placeholder to be displayed when the text field is in focus and the input text is empty. The default text style for internal Text is Typography.bodyLarge
the optional leading icon to be displayed at the beginning of the text field container
the optional trailing icon to be displayed at the end of the text field container
the optional prefix to be displayed before the input text in the text field
the optional suffix to be displayed after the input text in the text field
the optional supporting text to be displayed below the text field
indicates if the text field's current value is in error state. If set to true, the label, bottom indicator and trailing icon by default will be displayed in error color
transforms the visual representation of the input value. For example, you can use PasswordVisualTransformation to create a password text field. By default, no visual transformation is applied.
software keyboard options that contains configuration such as KeyboardType and ImeAction.
when the input service emits an IME action, the corresponding callback is called. Note that this IME action may be different from what you specified in KeyboardOptions.imeAction.
when true
, this text field becomes a single horizontally scrolling text field instead of wrapping onto multiple lines. The keyboard will be informed to not show the return key as the ImeAction. Note that maxLines parameter will be ignored as the maxLines attribute will be automatically set to 1.
the maximum height in terms of maximum number of visible lines. It is required that 1 <= minLines<= maxLines. This parameter is ignored when singleLine is true.
the minimum height in terms of minimum number of visible lines. It is required that 1 <= minLines<= maxLines. This parameter is ignored when singleLine is true.
an optional hoisted MutableInteractionSource for observing and emitting Interactions for this text field. You can use this to change the text field's appearance or preview the text field in different states. Note that if null
is provided, interactions will still happen internally.
defines the shape of this text field's container
TextFieldColors that will be used to resolve the colors used for this text field in different states. See TextFieldDefaults.colors.