SecureTextField
Functions summary
Unit |
@Composable |
Cmn
|
Functions
SecureTextField
@Composable
fun SecureTextField(
state: TextFieldState,
modifier: Modifier = Modifier,
enabled: Boolean = true,
textStyle: TextStyle = LocalTextStyle.current,
label: (@Composable () -> Unit)? = null,
placeholder: (@Composable () -> Unit)? = null,
leadingIcon: (@Composable () -> Unit)? = null,
trailingIcon: (@Composable () -> Unit)? = null,
isError: Boolean = false,
inputTransformation: InputTransformation? = null,
textObfuscationMode: TextObfuscationMode = TextObfuscationMode.System,
textObfuscationCharacter: Char = DefaultObfuscationCharacter,
keyboardOptions: KeyboardOptions = SecureTextFieldKeyboardOptions,
onKeyboardAction: KeyboardActionHandler? = null,
shape: Shape = TextFieldDefaults.TextFieldShape,
colors: TextFieldColors = TextFieldDefaults.textFieldColors(),
interactionSource: MutableInteractionSource? = null
): Unit
Material Design filled text field for secure content
Text fields allow users to enter text into a UI. SecureTextField is specifically designed for password entry fields. It only supports a single line of content and comes with default settings that are appropriate for entering secure content. Additionally, some context menu actions like cut, copy, and drag are disabled for added security.
Filled text fields have more visual emphasis than outlined text fields, making them stand out when surrounded by other content and components. For an outlined version, see OutlinedSecureTextField.
Example of a password text field:
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.input.TextObfuscationMode import androidx.compose.foundation.text.input.rememberTextFieldState import androidx.compose.material.Icon import androidx.compose.material.IconButton import androidx.compose.material.SecureTextField import androidx.compose.material.Text import androidx.compose.material.TextField import androidx.compose.material.icons.Icons import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.ui.text.input.KeyboardType var passwordHidden by rememberSaveable { mutableStateOf(true) } SecureTextField( state = rememberTextFieldState(), label = { Text("Enter password") }, keyboardOptions = KeyboardOptions( autoCorrectEnabled = false, keyboardType = if (passwordHidden) KeyboardType.Password else KeyboardType.PasswordVisible, ), textObfuscationMode = if (passwordHidden) TextObfuscationMode.System else TextObfuscationMode.Visible, trailingIcon = { IconButton(onClick = { passwordHidden = !passwordHidden }) { val visibilityIcon = if (passwordHidden) Icons.Filled.Visibility else Icons.Filled.VisibilityOff // Provide localized description for accessibility services val description = if (passwordHidden) "Show password" else "Hide password" Icon(imageVector = visibilityIcon, contentDescription = description) } }, )
| Parameters | |
|---|---|
state: TextFieldState |
|
modifier: Modifier = Modifier |
a |
enabled: Boolean = true |
controls the enabled state of the |
textStyle: TextStyle = LocalTextStyle.current |
the style to be applied to the input text. The default |
label: (@Composable () -> Unit)? = null |
the optional label to be displayed inside the text field container. The default text style for internal |
placeholder: (@Composable () -> Unit)? = null |
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 |
leadingIcon: (@Composable () -> Unit)? = null |
the optional leading icon to be displayed at the beginning of the text field container. |
trailingIcon: (@Composable () -> Unit)? = null |
the optional trailing icon to be displayed at the end of the text field container. |
isError: Boolean = false |
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. |
inputTransformation: InputTransformation? = null |
Optional |
textObfuscationMode: TextObfuscationMode = TextObfuscationMode.System |
the method used to obscure the input text. |
textObfuscationCharacter: Char = DefaultObfuscationCharacter |
the character to use while obfuscating the text. It doesn't have an effect when |
keyboardOptions: KeyboardOptions = SecureTextFieldKeyboardOptions |
software keyboard options that contains configuration such as |
onKeyboardAction: KeyboardActionHandler? = null |
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., |
shape: Shape = TextFieldDefaults.TextFieldShape |
the shape of the text field's container |
colors: TextFieldColors = TextFieldDefaults.textFieldColors() |
|
interactionSource: MutableInteractionSource? = null |
an optional hoisted |