簡體   English   中英

如何刪除 TextField 下面的下划線?

[英]How to remove underline below TextField?

這是代碼。 我想刪除文本下方的黑色下划線,目前 TextField 處於編輯模式:

TextField(
      autofocus: true,
      decoration: InputDecoration.collapsed(
        hintText: "Search",
        border: InputBorder.none,
      ),
      maxLines: 1,
    )

嘗試為您的 TextField 小部件提供 TextStyle。 您的 TextField 正在獲取您的默認主題的 TextStyle。

TextField(
      autofocus: true,
      style: TextStyle(color: Colors.white, fontSize: 30),
      decoration: InputDecoration.collapsed(
        hintText: "Search",
        border: InputBorder.none,
      ),
      maxLines: 1,
    )

在 TextField 小部件源代碼中,它指出:

  /// If null, defaults to the `subhead` text style from the current [Theme].
  final TextStyle style;

您應該在decoration屬性中使用TextDecoration.none

Text(
  'your txt',
  style: TextStyle( decoration: TextDecoration.none),
)

我懷疑這與預測文本有關。 當您按空格鍵結束正在輸入的單詞時,下划線消失; 當您開始輸入下一個單詞時,它們會再次出現。 按照這里的建議,嘗試設置TextInputType.visiblePassword; - 這對我有用。

https://stackoverflow.com/a/57499189/445887 所述

這是 Android 鍵盤的輔助功能(如果在TextStyle禁用它后仍然看到下划線)。

只是代碼...

TextFormField(
  decoration: InputDecoration(
                 hintText: 'comment..',
                 focusedBorder: InputBorder.none,
                 enabledBorder: InputBorder.none,
                 contentPadding: EdgeInsetsDirectional.only(start: 10.0),
                  ),
              )

喜歡這張圖片

然后在鍵入 use 時輸入文本總是帶有下划線:

autocorrect: false,
enableSuggestions: false,

https://stackoverflow.com/a/69921656/10932271

Provide the following code inside the TextField widget and change the color according to the background color of a TextField. If the background is white provide white color which will make the underline invisible.



style: TextStyle(
              fontSize: 16,
              letterSpacing: 1,
              decoration: TextDecoration.none,
              decorationStyle: TextDecorationStyle.dotted,
              decorationColor: Colors.white),

風格:TextStyle(decorationThickness:0)

你必須添加一個“decoration:TextDecoration.none”,像這樣:

  Text(
    "Don't forget",
    style: TextStyle(
       decoration: TextDecoration.none
    )
  )

@Immortal Dude是對的,這不是文本字段的問題。 因為在文本字段中輸入后單擊其他地方時,下划線會自動從文本中刪除。

您只需要設置鍵盤類型:

keyboardType: TextInputType.visiblePassword,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM