I'm using Jetpack Compose and want to customize the appearance of a BasicTextField to remove the underline when displaying text. I tried setting the keyboardOptions to KeyboardOptions(keyboardType = KeyboardType.Password)
as it effectively removes the underline.
However, this approach introduces a UX issue: when users copy text, the keyboard clipboard behaves like it’s handling a password field. For example, clipboard suggestions are shown as masked characters, which is not what I want.
Here’s the code I’m working
BasicTextField(
state = state,
modifier = Modifier
.fillMaxWidth()
.padding(20.dp),
interactionSource = interactionSource,
enabled = true,
lineLimits = TextFieldLineLimits.SingleLine,
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Text,
autoCorrectEnabled = false
),
textStyle = LocalTextStyle.current,
decorator = TextFieldDefaults.decorator(
state = state,
enabled = true,
lineLimits = TextFieldLineLimits.Default,
interactionSource = interactionSource,
outputTransformation = null,
),
)
What I need is a way to remove the underline from the BasicTextField
while retaining normal keyboard and clipboard behavior.
How can I achieve this? Is there a better way to customize the underline appearance without relying on KeyboardType.Password
? Any guidance or examples would be greatly appreciated!
Please refer dfdfg
text underline.
I'm using Jetpack Compose and want to customize the appearance of a BasicTextField to remove the underline when displaying text. I tried setting the keyboardOptions to KeyboardOptions(keyboardType = KeyboardType.Password)
as it effectively removes the underline.
However, this approach introduces a UX issue: when users copy text, the keyboard clipboard behaves like it’s handling a password field. For example, clipboard suggestions are shown as masked characters, which is not what I want.
Here’s the code I’m working
BasicTextField(
state = state,
modifier = Modifier
.fillMaxWidth()
.padding(20.dp),
interactionSource = interactionSource,
enabled = true,
lineLimits = TextFieldLineLimits.SingleLine,
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Text,
autoCorrectEnabled = false
),
textStyle = LocalTextStyle.current,
decorator = TextFieldDefaults.decorator(
state = state,
enabled = true,
lineLimits = TextFieldLineLimits.Default,
interactionSource = interactionSource,
outputTransformation = null,
),
)
What I need is a way to remove the underline from the BasicTextField
while retaining normal keyboard and clipboard behavior.
How can I achieve this? Is there a better way to customize the underline appearance without relying on KeyboardType.Password
? Any guidance or examples would be greatly appreciated!
Please refer dfdfg
text underline.
1 Answer
Reset to default -1As I mentioned in the comment, it is probably due to the keyboard's word prediction (which is why it stops for KeyboardType.Password).
You set the autoCorrectEnable parameter to false, but based on this answer:
Most keyboard implementations ignore this value for KeyboardTypes such as KeyboardType.Text.
Therefore, you will need to change this type to another one (perhaps KeyboardType.Email, as also mentioned in the linked answer).
2025.01.00
at the time of writing). – tyg Commented Jan 20 at 19:14