BasicSecureTextField
Common
Component in Compose Foundation
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.8.0-alpha04")
}
Overloads
@Suppress("ComposableLambdaParameterPosition")
@Composable
fun BasicSecureTextField(
state: TextFieldState,
modifier: Modifier = Modifier,
enabled: Boolean = true,
readOnly: Boolean = false,
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
name | description |
---|---|
state | [TextFieldState] object that holds the internal state of a [BasicSecureTextField]. |
modifier | optional [Modifier] for this text field. |
enabled | controls the enabled state of the [BasicSecureTextField]. When false , the text field will be neither editable nor focusable, the input of the text field will not be selectable. |
readOnly | controls the editable state of the [BasicSecureTextField]. When true , the text field can not be modified, however, a user can focus on it. Read-only text fields are usually used to display pre-filled forms that a user can not edit. |
inputTransformation | Optional [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]. |
textStyle | Style configuration for text content that's displayed in the editor. |
keyboardOptions | Software 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]. |
onKeyboardAction | Called 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. |
onTextLayout | Callback 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. |
interactionSource | the [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. |
decorator | Allows 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. |
textObfuscationMode | Determines the method used to obscure the input text. |
textObfuscationCharacter | Which character to use while obfuscating the text. It doesn't have an effect when [textObfuscationMode] is set to [TextObfuscationMode.Visible]. |
@Deprecated(
message = "Please use the overload that takes in readOnly parameter.",
level = DeprecationLevel.HIDDEN
)
@Suppress("ComposableLambdaParameterPosition")
@Composable
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,
)