【问题标题】:How modify the highlight color of TextField when tapped ? (Flutter)点击时如何修改TextField的高亮颜色? (扑)
【发布时间】:2021-05-05 04:47:35
【问题描述】:

我试图在聚焦时更改我的 labelText 颜色。我可以更改文本颜色,但不能在聚焦时更改。在下面的屏幕截图中,字符串“Email”在聚焦时保持蓝色。

这就是我所拥有的:

Container(
  margin: EdgeInsets.symmetric(horizontal: 600),
  child: TextField(
    decoration: InputDecoration(
      border: UnderlineInputBorder(),
      labelText: 'Email',
      suffix: Icon(
        Icons.check,
      ),
    ),
  ),
),
                  

这是按钮在按下之前的样子。

按下时是这样的

如何将这些高光修改为黑色而不是浅蓝色?谢谢!

【问题讨论】:

标签: flutter flutter-layout


【解决方案1】:

有两种方法可以修改 TextField 的高亮颜色:

  1. 使用InputDecoration(如果您想在本地修改单个TextField,请执行此操作)
Container(
  child: TextField(
    decoration: InputDecoration(
      focusedBorder: UnderlineInputBorder(
        borderSide: BorderSide(color: Colors.black),
      ),
      labelText: 'Email',
      labelStyle: TextStyle(color: Colors.black),
      suffix: Icon(
        Icons.check,
      ),
    ),
  ),
)
  1. 配置MaterialApp 小部件的theme 属性(如果您想为所有TextField 小部件设置通用主题,请执行此操作):
MaterialApp(
      theme: ThemeData(
          inputDecorationTheme: InputDecorationTheme(
        focusedBorder:
            UnderlineInputBorder(borderSide: BorderSide(color: Colors.black)),
        labelStyle: TextStyle(color: Colors.black),
      ),
   ),
   home: SomeScreen(),
);

【讨论】:

    【解决方案2】:

    尝试改变你的 inputDecoration labelStyle:

    InputDecorationTheme(
          labelStyle: TextStyle(
        color: black,
        fontSize: 12,
      );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-04
      • 2011-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多