如何更改textField的下划线颜色?

10 浏览
0 Comments

如何更改textField的下划线颜色?

我对Flutter和Dart都还不熟悉。目前,在我的一个个人项目中使用它。

在我的所有表单中,textField的下划线显示为蓝色。我想将其更改为其他颜色。我正在使用的代码如下...

new TextField(

controller: this._emailController,

decoration: new InputDecoration(

hintText: "输入您的电子邮件",

labelText: "电子邮件",

labelStyle: new TextStyle(

color: const Color(0xFF424242)

)

),

),

我不明白如何实现这一点。

注意:我知道这里有一个类似的问题Change TextField's Underline in Flutter。但是,在那里也没有完全解决。还有一个更类似于我的链接Changing EditText bottom line color with appcompat v7,但是,那实际上属于使用JAVA而不是我用于我的Android应用开发的DART(flutter)。所以,请不要对这些链接感到困惑。

0
0 Comments

问题的出现原因:需要改变文本框(textField)下划线的颜色。

解决方法:使用Flutter中的ThemeData类的inputDecorationTheme属性来改变整个应用程序的颜色,或者使用focusedBorder、enabledBorder和border属性来改变输入框在不同状态下的颜色。

具体代码如下:

1. 若要仅在输入框被选中且准备输入时改变颜色:

MaterialApp(

...

theme: ThemeData(

inputDecorationTheme: InputDecorationTheme(

focusedBorder: UnderlineInputBorder(

borderSide: BorderSide(color: Colors.red)

),

)

)

)

2. 若要始终使用相同的颜色,无论是否选中输入框,还需设置enabledBorder和border属性:

MaterialApp(

...

theme: ThemeData(

inputDecorationTheme: InputDecorationTheme(

focusedBorder: UnderlineInputBorder(

borderSide: BorderSide(color: Colors.red)

),

enabledBorder: UnderlineInputBorder(

borderSide: BorderSide(color: Colors.red),

),

border: UnderlineInputBorder(

borderSide: BorderSide(color: Colors.red),

),

)

)

)

以上就是解决问题的方法。希望能对你有所帮助。谢谢!

0
0 Comments

问题原因:想要改变TextField下划线的颜色,但是使用UnderlineInputBorder并不能直接改变颜色,因为TextField下划线的颜色是基于主题的。

解决方法:可以通过改变主题的方式来改变TextField下划线的颜色。可以使用Theme组件来指定整个应用程序的主题,然后在TextField的decoration中使用UnderlineInputBorder来设置下划线的颜色。

更新:现在可以按照预期的方式进行设置。可以在TextField的decoration中使用enabledBorder、focusedBorder和border属性来分别设置不同状态下下划线的颜色。

以下是代码示例:

decoration: InputDecoration(

enabledBorder: UnderlineInputBorder(

borderSide: BorderSide(color: theColor),

),

focusedBorder: UnderlineInputBorder(

borderSide: BorderSide(color: theColor),

),

border: UnderlineInputBorder(

borderSide: BorderSide(color: theColor),

),

)

注意:在整个应用程序中指定主题,并在需要的地方使用它,可能是更好的选择。这样可以方便地更改整个主题。

如果有人在我之前回答了这个问题,那么我会再次检查并添加代码示例。

通过改变主题的方式,或者使用enabledBorder、focusedBorder和border属性,可以改变TextField下划线的颜色。

0
0 Comments

问题的原因是用户想知道如何更改TextField下划线的颜色。解决方法是使用decoration属性来设置TextField的输入装饰,其中包括enabledBorder和focusedBorder属性来定义TextField的边框样式。具体的代码如下:

decoration: InputDecoration(

enabledBorder: UnderlineInputBorder(

borderSide: BorderSide(color: Colors.cyan),

),

focusedBorder: UnderlineInputBorder(

borderSide: BorderSide(color: Colors.cyan),

),

),

用户还提到了尝试使用Material App Theme设置来更改颜色系统,以及在InputDecoration.collapsed上应用enabledBorder的问题。

0