New Compose Multiplatform components arrived on Composables UICheck it out →

Component in Compose Foundation

BasicSecureTextField

Common

BasicSecureTextField is specifically designed for password entry fields and is a preconfigured alternative to [BasicTextField]. It only supports a single line of content and comes with default settings for [KeyboardOptions], [InputTransformation], and [CodepointTransformation] that are appropriate for entering secure content. Additionally, some context menu actions like cut, copy, and drag are disabled for added security.

Last updated:

Installation

dependencies {
   implementation("androidx.compose.foundation:foundation:1.7.0-beta04")
}

Overloads

@Composable
@Suppress("ComposableLambdaParameterPosition"
fun BasicSecureTextField(
    state: TextFieldState,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    inputTransformation: InputTransformation? = null,
    textStyle: TextStyle = TextStyle.Default,
    keyboardOptions: KeyboardOptions = KeyboardOptions.SecureTextField,
    onKeyboardAction: KeyboardActionHandler? = null,
    onTextLayout: (Density.(getResult: () -> TextLayoutResult?) -> Unit)? = null,
    interactionSource: MutableInteractionSource? = null,
    cursorBrush: Brush = SolidColor(Color.Black),
    decorator: TextFieldDecorator? = null,
    // Last parameter must not be a function unless it's intended to be commonly used as a trailing
    // lambda.
    textObfuscationMode: TextObfuscationMode = TextObfuscationMode.RevealLastTyped,
    textObfuscationCharacter: Char = DefaultObfuscationCharacter,
)

Parameters

namedescription
state[TextFieldState] object that holds the internal state of a [BasicTextField].
modifieroptional [Modifier] for this text field.
enabledcontrols the enabled state of the [BasicTextField]. When false, the text field will be neither editable nor focusable, the input of the text field will not be selectable.
inputTransformationOptional [InputTransformation] that will be used to transform changes to the [TextFieldState] made by the user. The transformation will be applied to changes made by hardware and software keyboard events, pasting or dropping text, accessibility services, and tests. The transformation will not be applied when changing the [state] programmatically, or when the transformation is changed. If the transformation is changed on an existing text field, it will be applied to the next user edit. The transformation will not immediately affect the current [state].
textStyleStyle configuration for text content that's displayed in the editor.
keyboardOptionsSoftware keyboard options that contain configurations such as [KeyboardType] and [ImeAction]. This composable by default configures [KeyboardOptions] for a secure text field by disabling auto correct and setting [KeyboardType] to [KeyboardType.Password].
onKeyboardActionCalled when the user presses the action button in the input method editor (IME), or by pressing the enter key on a hardware keyboard. By default this parameter is null, and would execute the default behavior for a received IME Action e.g., [ImeAction.Done] would close the keyboard, [ImeAction.Next] would switch the focus to the next focusable item on the screen.
onTextLayoutCallback that is executed when the text layout becomes queryable. The callback receives a function that returns a [TextLayoutResult] if the layout can be calculated, or null if it cannot. The function reads the layout result from a snapshot state object, and will invalidate its caller when the layout result changes. A [TextLayoutResult] object contains paragraph information, size of the text, baselines and other details. The callback can be used to add additional decoration or functionality to the text. For example, to draw a cursor or selection around the text. [Density] scope is the one that was used while creating the given text layout.
interactionSourcethe [MutableInteractionSource] representing the stream of [Interaction]s for this TextField. You can create and pass in your own remembered [MutableInteractionSource] if you want to observe [Interaction]s and customize the appearance / behavior of this TextField for different [Interaction]s.
cursorBrush[Brush] to paint cursor with. If [SolidColor] with [Color.Unspecified] provided, there will be no cursor drawn.
decoratorAllows to add decorations around text field, such as icon, placeholder, helper messages or similar, and automatically increase the hit target area of the text field.
textObfuscationModeDetermines the method used to obscure the input text.
textObfuscationCharacterWhich character to use while obfuscating the text. It doesn't have an effect when [textObfuscationMode] is set to [TextObfuscationMode.Visible].