TextField

fun TextField(state: TextFieldState, modifier: Modifier = Modifier, backgroundMode: TextFieldMode = TextFieldMode.Line, insideMargin: DpSize = TextFieldDefaults.insideMargin(backgroundMode), colors: TextFieldColors = TextFieldDefaults.textFieldColors(), cornerRadius: Dp = TextFieldDefaults.CornerRadius, label: String = "", useLabelAsPlaceholder: Boolean = true, justShowFocusLine: Boolean = false, enabled: Boolean = true, readOnly: Boolean = false, isError: Boolean = false, maxCount: Int? = null, showClearButton: Boolean = false, showPasswordToggle: Boolean = false, inputTransformation: InputTransformation? = null, textStyle: TextStyle = TextFieldDefaults.textStyle(backgroundMode), keyboardOptions: KeyboardOptions = KeyboardOptions.Default, onKeyboardAction: KeyboardActionHandler? = null, lineLimits: TextFieldLineLimits = TextFieldLineLimits.Default, leadingIcon: @Composable () -> Unit? = null, trailingIcon: @Composable () -> Unit? = null, onTextLayout: Density.(getResult: () -> TextLayoutResult?) -> Unit? = null, interactionSource: MutableInteractionSource? = null, cursorBrush: Brush = SolidColor(colors.borderColor), outputTransformation: OutputTransformation? = null, scrollState: ScrollState = rememberScrollState())

A TextField component with COUI style.

Parameters

state

The TextFieldState to be shown in the text field.

modifier

The modifier to be applied to the TextField.

backgroundMode

The TextFieldMode of the background decoration. Defaults to TextFieldMode.Line, the form ColorOS Settings uses for dialog / panel inputs.

insideMargin

The margin inside the TextField. Defaults to the COUI padding of the selected backgroundMode.

colors

The TextFieldColors applied to the TextField. Use TextFieldDefaults.textFieldColors to customize.

cornerRadius

The corner radius of the TextField (only used by TextFieldMode.Rectangle).

label

The label (hint) to be displayed when the TextField is empty.

useLabelAsPlaceholder

Whether the label behaves as a plain placeholder that disappears once text is entered (COUI default). Set to false to enable the COUI HintAnim floating-label animation.

justShowFocusLine

Only used by TextFieldMode.Line: hide the resting underline and show just the focused expanding line, mirroring COUIInputPreference couiJustShowFocusLine.

enabled

Whether the TextField is enabled.

readOnly

Whether the TextField is read-only.

isError

Whether the TextField is in error state. Turning this on tints the border / underline and label with TextFieldColors.errorColor and plays a horizontal shake animation, mirroring COUIErrorEditTextHelper.

maxCount

The maximum number of characters. When not null a "count/max" counter is shown at the end and input is truncated at maxCount, mirroring COUIInputView couiInputMaxCount.

showClearButton

Whether to show a clear (fast delete) button when the TextField is focused and not empty, mirroring COUIEditText quickDelete.

showPasswordToggle

Whether to show an eye toggle that switches the password visibility, mirroring COUIInputView couiEnablePassword. While the password is hidden, the text is masked and outputTransformation is ignored.

inputTransformation

The input transformation to be applied to the TextField.

textStyle

The text style to be applied to the TextField. Defaults to the COUI input text of the selected backgroundMode: 16sp regular (couiEditTextTextAppearance), bold in TextFieldMode.Rectangle (Widget.COUI.EditText.HintAnim.Rectangle android:textStyle=bold).

keyboardOptions

The keyboard options to be applied to the TextField.

onKeyboardAction

The keyboard action handler for the TextField.

lineLimits

The line limits for the TextField.

leadingIcon

The leading icon to be displayed in the TextField.

trailingIcon

The trailing icon to be displayed in the TextField.

onTextLayout

The callback to be called when the text layout changes.

interactionSource

The interaction source to be applied to the TextField.

cursorBrush

The brush to be used for the cursor.

outputTransformation

The output transformation for the text field.

scrollState

The scroll state for the text field.


fun TextField(value: TextFieldValue, onValueChange: (TextFieldValue) -> Unit, modifier: Modifier = Modifier, backgroundMode: TextFieldMode = TextFieldMode.Line, insideMargin: DpSize = TextFieldDefaults.insideMargin(backgroundMode), colors: TextFieldColors = TextFieldDefaults.textFieldColors(), cornerRadius: Dp = TextFieldDefaults.CornerRadius, label: String = "", useLabelAsPlaceholder: Boolean = true, justShowFocusLine: Boolean = false, enabled: Boolean = true, readOnly: Boolean = false, isError: Boolean = false, maxCount: Int? = null, showClearButton: Boolean = false, showPasswordToggle: Boolean = false, textStyle: TextStyle = TextFieldDefaults.textStyle(backgroundMode), keyboardOptions: KeyboardOptions = KeyboardOptions.Default, keyboardActions: KeyboardActions = KeyboardActions.Default, leadingIcon: @Composable () -> Unit? = null, trailingIcon: @Composable () -> Unit? = null, singleLine: Boolean = false, maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE, minLines: Int = 1, visualTransformation: VisualTransformation = VisualTransformation.None, onTextLayout: (TextLayoutResult) -> Unit = {}, interactionSource: MutableInteractionSource? = null, cursorBrush: Brush = SolidColor(colors.borderColor))

A TextField component with COUI style.

Parameters

value

The input TextFieldValue to be shown in the text field.

onValueChange

The callback that is triggered when the input service updates values in TextFieldValue. An updated TextFieldValue comes as a parameter of the callback.

modifier

The modifier to be applied to the TextField.

backgroundMode

The TextFieldMode of the background decoration. Defaults to TextFieldMode.Line, the form ColorOS Settings uses for dialog / panel inputs.

insideMargin

The margin inside the TextField. Defaults to the COUI padding of the selected backgroundMode.

colors

The TextFieldColors applied to the TextField. Use TextFieldDefaults.textFieldColors to customize.

cornerRadius

The corner radius of the TextField (only used by TextFieldMode.Rectangle).

label

The label (hint) to be displayed when the TextField is empty.

useLabelAsPlaceholder

Whether the label behaves as a plain placeholder that disappears once text is entered (COUI default). Set to false to enable the COUI HintAnim floating-label animation.

justShowFocusLine

Only used by TextFieldMode.Line: hide the resting underline and show just the focused expanding line, mirroring COUIInputPreference couiJustShowFocusLine.

enabled

Whether the TextField is enabled.

readOnly

Whether the TextField is read-only.

isError

Whether the TextField is in error state. Turning this on tints the border / underline and label with TextFieldColors.errorColor and plays a horizontal shake animation, mirroring COUIErrorEditTextHelper.

maxCount

The maximum number of characters. When not null a "count/max" counter is shown at the end and input is truncated at maxCount, mirroring COUIInputView couiInputMaxCount.

showClearButton

Whether to show a clear (fast delete) button when the TextField is focused and not empty, mirroring COUIEditText quickDelete.

showPasswordToggle

Whether to show an eye toggle that switches the password visibility, mirroring COUIInputView couiEnablePassword. While the password is hidden, the text is masked and visualTransformation is ignored.

textStyle

The text style to be applied to the TextField. Defaults to the COUI input text of the selected backgroundMode.

keyboardOptions

The keyboard options to be applied to the TextField.

keyboardActions

The keyboard actions to be applied to the TextField.

leadingIcon

The leading icon to be displayed in the TextField.

trailingIcon

The trailing icon to be displayed in the TextField.

singleLine

Whether the text field is single line.

maxLines

The maximum number of lines allowed to be displayed in TextField.

minLines

The minimum number of lines allowed to be displayed in TextField. It is required that 1 <= minLines<= maxLines.

visualTransformation

The visual transformation to be applied to the TextField.

onTextLayout

The callback to be called when the text layout changes.

interactionSource

The interaction source to be applied to the TextField.

cursorBrush

The brush to be used for the cursor.


fun TextField(value: String, onValueChange: (String) -> Unit, modifier: Modifier = Modifier, backgroundMode: TextFieldMode = TextFieldMode.Line, insideMargin: DpSize = TextFieldDefaults.insideMargin(backgroundMode), colors: TextFieldColors = TextFieldDefaults.textFieldColors(), cornerRadius: Dp = TextFieldDefaults.CornerRadius, label: String = "", useLabelAsPlaceholder: Boolean = true, justShowFocusLine: Boolean = false, enabled: Boolean = true, readOnly: Boolean = false, isError: Boolean = false, maxCount: Int? = null, showClearButton: Boolean = false, showPasswordToggle: Boolean = false, textStyle: TextStyle = TextFieldDefaults.textStyle(backgroundMode), keyboardOptions: KeyboardOptions = KeyboardOptions.Default, keyboardActions: KeyboardActions = KeyboardActions.Default, leadingIcon: @Composable () -> Unit? = null, trailingIcon: @Composable () -> Unit? = null, singleLine: Boolean = false, maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE, minLines: Int = 1, visualTransformation: VisualTransformation = VisualTransformation.None, onTextLayout: (TextLayoutResult) -> Unit = {}, interactionSource: MutableInteractionSource? = null, cursorBrush: Brush = SolidColor(colors.borderColor))

A text field component with COUI style.

Parameters

value

The text to be displayed in the text field.

onValueChange

The callback to be called when the value changes.

modifier

The modifier to be applied to the TextField.

backgroundMode

The TextFieldMode of the background decoration. Defaults to TextFieldMode.Line, the form ColorOS Settings uses for dialog / panel inputs.

insideMargin

The margin inside the TextField. Defaults to the COUI padding of the selected backgroundMode.

colors

The TextFieldColors applied to the TextField. Use TextFieldDefaults.textFieldColors to customize.

cornerRadius

The corner radius of the TextField (only used by TextFieldMode.Rectangle).

label

The label (hint) to be displayed when the TextField is empty.

useLabelAsPlaceholder

Whether the label behaves as a plain placeholder that disappears once text is entered (COUI default). Set to false to enable the COUI HintAnim floating-label animation.

justShowFocusLine

Only used by TextFieldMode.Line: hide the resting underline and show just the focused expanding line, mirroring COUIInputPreference couiJustShowFocusLine.

enabled

Whether the TextField is enabled.

readOnly

Whether the TextField is read-only.

isError

Whether the TextField is in error state. Turning this on tints the border / underline and label with TextFieldColors.errorColor and plays a horizontal shake animation, mirroring COUIErrorEditTextHelper.

maxCount

The maximum number of characters. When not null a "count/max" counter is shown at the end and input is truncated at maxCount, mirroring COUIInputView couiInputMaxCount.

showClearButton

Whether to show a clear (fast delete) button when the TextField is focused and not empty, mirroring COUIEditText quickDelete.

showPasswordToggle

Whether to show an eye toggle that switches the password visibility, mirroring COUIInputView couiEnablePassword. While the password is hidden, the text is masked and visualTransformation is ignored.

textStyle

The text style to be applied to the TextField. Defaults to the COUI input text of the selected backgroundMode.

keyboardOptions

The keyboard options to be applied to the TextField.

keyboardActions

The keyboard actions to be applied to the TextField.

leadingIcon

The leading icon to be displayed in the TextField.

trailingIcon

The trailing icon to be displayed in the TextField.

singleLine

Whether the text field is single line.

maxLines

The maximum number of lines allowed to be displayed in TextField.

minLines

The minimum number of lines allowed to be displayed in TextField. It is required that 1 <= minLines<= maxLines.

visualTransformation

The visual transformation to be applied to the TextField.

onTextLayout

The callback to be called when the text layout changes.

interactionSource

The interaction source to be applied to the TextField.

cursorBrush

The brush to be used for the cursor.