You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中如何修改TextField标签的字体样式与大小?

如何修改TextField标签的字体与大小?

当然可以修改TextField的标签字体与大小,你只需要在InputDecoration中通过labelStyle属性指定自定义的TextStyle即可,修改后的代码示例如下:

TextField(
  controller: _dateController,
  decoration: const InputDecoration(
    labelText: 'Date',
    // 自定义标签样式
    labelStyle: TextStyle(
      fontSize: 16, // 设置字体大小
      fontFamily: 'Arial', // 设置字体
      color: Colors.grey, // 设置字体颜色
      fontWeight: FontWeight.w500, // 设置字体粗细
    ),
    border: OutlineInputBorder(),
  ),
)

你可以根据需求调整TextStyle中的参数,比如修改fontSize调整大小,更换fontFamily切换字体,还能设置字体颜色、粗细等其他样式。

内容的提问来源于stack exchange,提问作者kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 02:10:54