【问题标题】:How to remove underline below TextField?如何删除TextField下方的下划线?
【发布时间】:2019-05-26 16:43:23
【问题描述】:

这里是代码。我想删除文本正下方的黑色下划线,当前 TextField 处于编辑模式:

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

【问题讨论】:

  • 你在热加载吗?如果是这样,请停止应用程序并再次运行它
  • 我一次又一次地冷启动,但没有成功
  • 让我们看看这是否有帮助:TextField(..., style: TextStyle(decoration: TextDecoration.none))
  • @RahulLohra 这不是您可以控制的,而是您的键盘所做的(某种功能)。我要求您删除焦点的原因,即在您输入内容后点击字段外部是为了确认这一事实。这不是文本字段的问题,而是键盘的拼写检查器让您知道您输入的单词是正确的,如果您输入错误的内容,例如“wasdsasd”,黑线将变成红色下划线。而是禁用自动更正,请参阅:github.com/flutter/flutter/issues/22828#issuecomment-428093243

标签: flutter dart textfield


【解决方案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;

【讨论】:

    【解决方案2】:

    您应该在decoration 属性中使用TextDecoration.none。

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

    【讨论】:

      【解决方案3】:

      我怀疑这与预测文本有关。当您按空格键结束您正在输入的单词时,下划线会消失;然后,当您开始输入下一个单词时,它们会再次出现。按照here 的建议,尝试设置 TextInputType.visiblePassword; - 这对我有用。

      【讨论】:

        【解决方案4】:

        只需编码...

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

        【讨论】:

          【解决方案5】:

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

          这是 Android 键盘的辅助功能(如果您在 TextStyle 中禁用它后仍然看到下划线)。

          【讨论】:

            【解决方案6】:

            然后输入文本总是在输入时加下划线使用:

            autocorrect: false,
            enableSuggestions: false,
            

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

            【讨论】:

              【解决方案7】:

              你必须添加一个“decoration:TextDecoration.none”,像这样:

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

              【讨论】:

                【解决方案8】:

                @Immortal Dude 说得对,这不是文本字段的问题。因为当您在文本字段中键入后单击其他位置时,下划线会自动从文本中删除。

                你只需要设置键盘类型:

                keyboardType: TextInputType.visiblePassword,
                

                【讨论】:

                  猜你喜欢
                  • 2020-01-14
                  • 2013-11-10
                  • 1970-01-01
                  • 2016-04-04
                  • 2016-10-15
                  • 2016-08-26
                  • 2017-03-23
                  • 2018-09-11
                  • 1970-01-01
                  相关资源
                  最近更新 更多