object OutlinedTextFieldDefaults
Contains the default values used by OutlinedTextField. For defaults used in TextField, see TextFieldDefaults.
Properties
val shape: Shape
Default shape for an OutlinedTextField.
val MinHeight = 56.dp
The default min height applied to an OutlinedTextField. Note that you can override it by applying Modifier.heightIn directly on a text field.
val MinWidth = 280.dp
The default min width applied to an OutlinedTextField. Note that you can override it by applying Modifier.widthIn directly on a text field.
val UnfocusedBorderThickness = 1.dp
The default thickness of the border in OutlinedTextField in unfocused state.
val FocusedBorderThickness = 2.dp
The default thickness of the border in OutlinedTextField in focused state.
Functions
decorator
@Composable
fun decorator(
state: TextFieldState,
enabled: Boolean,
lineLimits: TextFieldLineLimits,
outputTransformation: OutputTransformation?,
interactionSource: InteractionSource,
labelPosition: TextFieldLabelPosition = TextFieldLabelPosition.Attached(),
label: @Composable (TextFieldLabelScope.() -> Unit)? = null,
placeholder: @Composable (() -> Unit)? = null,
leadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
prefix: @Composable (() -> Unit)? = null,
suffix: @Composable (() -> Unit)? = null,
supportingText: @Composable (() -> Unit)? = null,
isError: Boolean = false,
colors: TextFieldColors = colors(),
contentPadding: PaddingValues = contentPadding(),
container: @Composable () -> Unit = {
Container(
enabled = enabled,
isError = isError,
interactionSource = interactionSource,
colors = colors,
shape = shape,
focusedBorderThickness = FocusedBorderThickness,
unfocusedBorderThickness = UnfocusedBorderThickness,
)
},
): TextFieldDecorator
A decorator used to create custom text fields based on Material Design outlined text field.
If your text field requires customising elements that aren't exposed by OutlinedTextField, such as the border thickness, consider using this decorator to achieve the desired design.
For example, if you wish to customize the thickness of the border, you can pass a custom Container to this decoration box's container.
This decorator is meant to be used in conjunction with the overload of BasicTextField that accepts a TextFieldDecorator parameter. For other overloads of BasicTextField that use a decorationBox, see DecorationBox.
An example of building a custom text field using decorator:
Parameters
| state | TextFieldState object that holds the internal editing state of the text field. |
| enabled | the enabled state of the text field. When false, this decorator will appear visually disabled. This must be the same value that is passed to BasicTextField. |
| lineLimits | whether the text field is SingleLine or MultiLine. This must be the same value that is passed to BasicTextField. |
| outputTransformation | OutputTransformation that transforms how the contents of the text field are presented. This must be the same value that is passed to BasicTextField. |
| interactionSource | the read-only InteractionSource representing the stream of Interactions for this text field. You must first create and pass in your own remembered MutableInteractionSource instance to the BasicTextField for it to dispatch events. And then pass the same instance to this decorator to observe Interactions and customize the appearance/behavior of the text field in different states. |
| labelPosition | the position of the label. See TextFieldLabelPosition. |
| label | the optional label to be displayed with this text field. The default text style uses Typography.bodySmall when minimized and Typography.bodyLarge when expanded. |
| placeholder | the optional placeholder to be displayed when the input text is empty. The default text style uses Typography.bodyLarge. |
| leadingIcon | the optional leading icon to be displayed at the beginning of the text field container. |
| trailingIcon | the optional trailing icon to be displayed at the end of the text field container. |
| prefix | the optional prefix to be displayed before the input text in the text field. |
| suffix | the optional suffix to be displayed after the input text in the text field. |
| supportingText | the optional supporting text to be displayed below the text field. |
| isError | indicates if the text field's current value is in an error state. When true, this decorator will display its contents in an error color. |
| colors | TextFieldColors that will be used to resolve the colors used for this text field decorator in different states. See OutlinedTextFieldDefaults.colors. Note: This parameter only affects the colors of elements in the decoration box. Elements of the BasicTextField (such as text color or cursor color) are unaffected and must be changed using the relevant parameters of BasicTextField. |
| contentPadding | the padding between the input field and the surrounding elements of the decorator. Note that the padding values may not be respected if they are incompatible with the text field's size constraints or layout. See OutlinedTextFieldDefaults.contentPadding. |
| container | the container to be drawn behind the text field. By default, this is transparent and only includes a border. The cutout in the border to fit the label will be automatically added by the framework. Default colors for the container come from the colors. |
Container
@Composable
fun Container(
enabled: Boolean,
isError: Boolean,
interactionSource: InteractionSource,
modifier: Modifier = Modifier,
colors: TextFieldColors = colors(),
shape: Shape = OutlinedTextFieldDefaults.shape,
focusedBorderThickness: Dp = FocusedBorderThickness,
unfocusedBorderThickness: Dp = UnfocusedBorderThickness,
)
Composable that draws a default container for an OutlinedTextField with a border stroke. You can apply it to a BasicTextField using decorator or DecorationBox to create a custom text field based on the styling of a Material outlined text field. The OutlinedTextField component applies it automatically.
Parameters
| enabled | whether the text field is enabled |
| isError | whether the text field's current value is in error |
| interactionSource | the InteractionSource of the text field. Used to determine if the text field is in focus or not |
| modifier | the Modifier of this container |
| colors | TextFieldColors used to resolve colors of the text field |
| shape | the shape of this container |
| focusedBorderThickness | thickness of the border when the text field is focused |
| unfocusedBorderThickness | thickness of the border when the text field is not focused |
DecorationBox
@Composable
fun DecorationBox(
value: String,
innerTextField: @Composable () -> Unit,
enabled: Boolean,
singleLine: Boolean,
visualTransformation: VisualTransformation,
interactionSource: InteractionSource,
isError: Boolean = false,
label: @Composable (() -> Unit)? = null,
placeholder: @Composable (() -> Unit)? = null,
leadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
prefix: @Composable (() -> Unit)? = null,
suffix: @Composable (() -> Unit)? = null,
supportingText: @Composable (() -> Unit)? = null,
colors: TextFieldColors = colors(),
contentPadding: PaddingValues = contentPadding(),
container: @Composable () -> Unit = {
Container(
enabled = enabled,
isError = isError,
interactionSource = interactionSource,
modifier = Modifier,
colors = colors,
shape = shape,
focusedBorderThickness = FocusedBorderThickness,
unfocusedBorderThickness = UnfocusedBorderThickness,
)
},
)
A decoration box used to create custom text fields based on Material Design outlined text field.
If your text field requires customising elements that aren't exposed by OutlinedTextField, consider using this decoration box to achieve the desired design.
For example, if you wish to customize the thickness of the border, you can pass a custom Container to this decoration box's container.
This decoration box is meant to be used in conjunction with overloads of BasicTextField that accept a decorationBox parameter. For other overloads of BasicTextField that use a TextFieldDecorator, see decorator.
An example of building a custom text field using DecorationBox:
Parameters
| value | the input String shown by the text field |
| innerTextField | input text field that this decoration box wraps. Pass the framework-controlled composable parameter innerTextField from the decorationBox lambda of the BasicTextField |
| enabled | the enabled state of the text field. When false, this decoration box will appear visually disabled. This must be the same value that is passed to BasicTextField. |
| singleLine | indicates if this is a single line or multi line text field. This must be the same value that is passed to BasicTextField. |
| visualTransformation | transforms the visual representation of the input value. This must be the same value that is passed to BasicTextField. |
| interactionSource | the read-only InteractionSource representing the stream of Interactions for this text field. You must first create and pass in your own remembered MutableInteractionSource instance to the BasicTextField for it to dispatch events. And then pass the same instance to this decoration box to observe Interactions and customize the appearance / behavior of this text field in different states. |
| isError | indicates if the text field's current value is in an error state. When true, this decoration box will display its contents in an error color. |
| label | the optional label to be displayed with this text field. The default text style uses Typography.bodySmall when minimized and Typography.bodyLarge when expanded. |
| placeholder | 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. |
| leadingIcon | the optional leading icon to be displayed at the beginning of the text field container |
| trailingIcon | the optional trailing icon to be displayed at the end of the text field container |
| prefix | the optional prefix to be displayed before the input text in the text field |
| suffix | the optional suffix to be displayed after the input text in the text field |
| supportingText | the optional supporting text to be displayed below the text field |
| colors | TextFieldColors that will be used to resolve the colors used for this text field decoration box in different states. See OutlinedTextFieldDefaults.colors. Note: This parameter only affects the colors of elements in the decoration box. Elements of the BasicTextField (such as text color or cursor color) are unaffected and must be changed using the relevant parameters of BasicTextField. |
| contentPadding | the padding between the input field and the surrounding elements of the decoration box. Note that the padding values may not be respected if they are incompatible with the text field's size constraints or layout. See OutlinedTextFieldDefaults.contentPadding. |
| container | the container to be drawn behind the text field. By default, this is transparent and only includes a border. The cutout in the border to fit the label will be automatically added by the framework. Default colors for the container come from the colors. |
contentPadding
fun contentPadding(
start: Dp = TextFieldPadding,
top: Dp = TextFieldPadding,
end: Dp = TextFieldPadding,
bottom: Dp = TextFieldPadding,
): PaddingValues
Default content padding of the input field within the OutlinedTextField.
Horizontal padding represents the distance between the input field and the leading/trailing icons (if present) or the horizontal edges of the container if there are no icons.
@Composable fun colors() = MaterialTheme.colorScheme.defaultOutlinedTextFieldColors
Creates a TextFieldColors that represents the default input text, container, and content colors (including label, placeholder, icons, etc.) used in an OutlinedTextField.
colors
@Composable
fun colors(
focusedTextColor: Color = Color.Unspecified,
unfocusedTextColor: Color = Color.Unspecified,
disabledTextColor: Color = Color.Unspecified,
errorTextColor: Color = Color.Unspecified,
focusedContainerColor: Color = Color.Unspecified,
unfocusedContainerColor: Color = Color.Unspecified,
disabledContainerColor: Color = Color.Unspecified,
errorContainerColor: Color = Color.Unspecified,
cursorColor: Color = Color.Unspecified,
errorCursorColor: Color = Color.Unspecified,
selectionColors: TextSelectionColors? = null,
focusedBorderColor: Color = Color.Unspecified,
unfocusedBorderColor: Color = Color.Unspecified,
disabledBorderColor: Color = Color.Unspecified,
errorBorderColor: Color = Color.Unspecified,
focusedLeadingIconColor: Color = Color.Unspecified,
unfocusedLeadingIconColor: Color = Color.Unspecified,
disabledLeadingIconColor: Color = Color.Unspecified,
errorLeadingIconColor: Color = Color.Unspecified,
focusedTrailingIconColor: Color = Color.Unspecified,
unfocusedTrailingIconColor: Color = Color.Unspecified,
disabledTrailingIconColor: Color = Color.Unspecified,
errorTrailingIconColor: Color = Color.Unspecified,
focusedLabelColor: Color = Color.Unspecified,
unfocusedLabelColor: Color = Color.Unspecified,
disabledLabelColor: Color = Color.Unspecified,
errorLabelColor: Color = Color.Unspecified,
focusedPlaceholderColor: Color = Color.Unspecified,
unfocusedPlaceholderColor: Color = Color.Unspecified,
disabledPlaceholderColor: Color = Color.Unspecified,
errorPlaceholderColor: Color = Color.Unspecified,
focusedSupportingTextColor: Color = Color.Unspecified,
unfocusedSupportingTextColor: Color = Color.Unspecified,
disabledSupportingTextColor: Color = Color.Unspecified,
errorSupportingTextColor: Color = Color.Unspecified,
focusedPrefixColor: Color = Color.Unspecified,
unfocusedPrefixColor: Color = Color.Unspecified,
disabledPrefixColor: Color = Color.Unspecified,
errorPrefixColor: Color = Color.Unspecified,
focusedSuffixColor: Color = Color.Unspecified,
unfocusedSuffixColor: Color = Color.Unspecified,
disabledSuffixColor: Color = Color.Unspecified,
errorSuffixColor: Color = Color.Unspecified,
): TextFieldColors
Creates a TextFieldColors that represents the default input text, container, and content colors (including label, placeholder, icons, etc.) used in an OutlinedTextField.
Parameters
| focusedTextColor | the color used for the input text of this text field when focused |
| unfocusedTextColor | the color used for the input text of this text field when not focused |
| disabledTextColor | the color used for the input text of this text field when disabled |
| errorTextColor | the color used for the input text of this text field when in error state |
| focusedContainerColor | the container color for this text field when focused |
| unfocusedContainerColor | the container color for this text field when not focused |
| disabledContainerColor | the container color for this text field when disabled |
| errorContainerColor | the container color for this text field when in error state |
| cursorColor | the cursor color for this text field |
| errorCursorColor | the cursor color for this text field when in error state |
| selectionColors | the colors used when the input text of this text field is selected |
| focusedBorderColor | the border color for this text field when focused |
| unfocusedBorderColor | the border color for this text field when not focused |
| disabledBorderColor | the border color for this text field when disabled |
| errorBorderColor | the border color for this text field when in error state |
| focusedLeadingIconColor | the leading icon color for this text field when focused |
| unfocusedLeadingIconColor | the leading icon color for this text field when not focused |
| disabledLeadingIconColor | the leading icon color for this text field when disabled |
| errorLeadingIconColor | the leading icon color for this text field when in error state |
| focusedTrailingIconColor | the trailing icon color for this text field when focused |
| unfocusedTrailingIconColor | the trailing icon color for this text field when not focused |
| disabledTrailingIconColor | the trailing icon color for this text field when disabled |
| errorTrailingIconColor | the trailing icon color for this text field when in error state |
| focusedLabelColor | the label color for this text field when focused |
| unfocusedLabelColor | the label color for this text field when not focused |
| disabledLabelColor | the label color for this text field when disabled |
| errorLabelColor | the label color for this text field when in error state |
| focusedPlaceholderColor | the placeholder color for this text field when focused |
| unfocusedPlaceholderColor | the placeholder color for this text field when not focused |
| disabledPlaceholderColor | the placeholder color for this text field when disabled |
| errorPlaceholderColor | the placeholder color for this text field when in error state |
| focusedSupportingTextColor | the supporting text color for this text field when focused |
| unfocusedSupportingTextColor | the supporting text color for this text field when not focused |
| disabledSupportingTextColor | the supporting text color for this text field when disabled |
| errorSupportingTextColor | the supporting text color for this text field when in error state |
| focusedPrefixColor | the prefix color for this text field when focused |
| unfocusedPrefixColor | the prefix color for this text field when not focused |
| disabledPrefixColor | the prefix color for this text field when disabled |
| errorPrefixColor | the prefix color for this text field when in error state |
| focusedSuffixColor | the suffix color for this text field when focused |
| unfocusedSuffixColor | the suffix color for this text field when not focused |
| disabledSuffixColor | the suffix color for this text field when disabled |
| errorSuffixColor | the suffix color for this text field when in error state |
ContainerBox
@ExperimentalMaterial3Api
@Composable
fun ContainerBox(
enabled: Boolean,
isError: Boolean,
interactionSource: InteractionSource,
colors: TextFieldColors = colors(),
shape: Shape = OutlinedTextFieldDefaults.shape,
focusedBorderThickness: Dp = FocusedBorderThickness,
unfocusedBorderThickness: Dp = UnfocusedBorderThickness,
) =
Container(
enabled = enabled,
isError = isError,
interactionSource = interactionSource,
modifier = Modifier,
colors = colors,
shape = shape,
focusedBorderThickness = focusedBorderThickness,
unfocusedBorderThickness = unfocusedBorderThickness,
)