【问题标题】:How to change color style of TextField in flutter如何在颤动中更改TextField的颜色样式
【发布时间】:2021-07-05 22:37:50
【问题描述】:

我有一个像这样的简单 TextField 小部件

TextField(
      obscureText: widget.placeholder == "Password" ? _isHidePassword : false,
      decoration: InputDecoration(
        
        hintText: "${widget.placeholder}",
        hintStyle: TextStyle(
          color: Colors.grey,
        ),
        // labelText: "${widget.placeholder}",
        // labelStyle: TextStyle(color: greenMain),
      ),
    )

它给出的结果如下图:

有没有办法将蓝色变成另一种?喜欢红色还是绿色?

【问题讨论】:

    标签: flutter colors styles textfield


    【解决方案1】:

    让我们试试

    Theme(
            data: new ThemeData(
              primaryColor: Colors.redAccent,
              primaryColorDark: Colors.red,
            ),
            child: TextField(
              keyboardType: TextInputType.text,
              decoration: InputDecoration(
                
                labelText: "Text field*",
              ),
            ),
          ),
    

    【讨论】:

      【解决方案2】:

      你可以像这样使用TextField上的装饰:

      decoration: InputDecoration(
      hintText: 'Type Text Here',        
      enabledBorder: UnderlineInputBorder(      
      borderSide: BorderSide(color: Colors.red),   
      ), 
      

      这会将线条变为红色。

      希望能帮到你

      【讨论】:

      • 谢谢你的回答,我试过了,线条颜色变成红色,但是每当我点击TextForm时,颜色又会变成蓝色
      猜你喜欢
      • 2021-04-30
      • 1970-01-01
      • 2021-01-18
      • 2021-09-27
      • 2019-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多