最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - How to Remove Underline from text in Jetpack Compose BasicTextField - Stack Overflow

programmeradmin1浏览0评论

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.

Share Improve this question edited Jan 20 at 14:46 Vivek Modi asked Jan 20 at 14:18 Vivek ModiVivek Modi 7,15118 gold badges101 silver badges224 bronze badges 10
  • Which keyboard are you using on your device? – BenjyTec Commented Jan 20 at 15:46
  • Normal Gboard I'm using in my device. – Vivek Modi Commented Jan 20 at 16:32
  • I cannot reproduce the issue with the code you provided. The text is not underlined. Does this also occur when you create a new, empty project and just use the code from the question? Since you use some new features from BasicTextField you need to update to the newest Alpha Compose BOM first (2025.01.00 at the time of writing). – tyg Commented Jan 20 at 19:14
  • Yes I can see same problem in compose alpha – Vivek Modi Commented Jan 20 at 19:29
  • The important part was the new project, not the alpha version. The latter is just a necessity to make it run. So, can you still reproduce the issue with a new project? I can't. – tyg Commented Jan 20 at 19:32
 |  Show 5 more comments

1 Answer 1

Reset to default -1

As 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).

发布评论

评论列表(0)

  1. 暂无评论