如何更改 TextField 的高度和宽度? [英] How to change TextField's height and width?

查看:111
本文介绍了如何更改 TextField 的高度和宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何自定义TextFieldwidthheight?

推荐答案

要调整宽度,您可以用 Container 小部件包裹 TextField,如下所示:

To adjust the width, you could wrap your TextField with a Container widget, like so:

Container(              
  width: 100.0,
  child: TextField()
)

对于 TextField 的高度,我不太确定您想要的是什么,但您肯定可以看看 TextStyle 小部件,其中您可以操纵 fontSize 和/或 height

I'm not really sure what you're after when it comes to the height of the TextField but you could definitely have a look at the TextStyle widget, with which you can manipulate the fontSize and/or height

Container(              
  width: 100.0,
  child: TextField(                                 
    style: TextStyle(
      fontSize: 40.0,
      height: 2.0,
      color: Colors.black                  
    )
  )
)

请记住,根据属性本身的注释,TextStyle 中的 height 是字体大小的倍数:

Bear in mind that the height in the TextStyle is a multiplier of the font size, as per comments on the property itself:

此文本跨度的高度,作为字体大小的倍数.

The height of this text span, as a multiple of the font size.

当[height]为null或省略时,将确定行高直接通过字体的度量,这可能与 fontSize 不同.当 [height] 不为 null 时,文本跨度的行高将为[fontSize] 的倍数并且正好是 fontSize * height 逻辑像素高.

When [height] is null or omitted, the line height will be determined by the font's metrics directly, which may differ from the fontSize. When [height] is non-null, the line height of the span of text will be a multiple of [fontSize] and be exactly fontSize * height logical pixels tall.

最后但同样重要的是,您可能想看看 TextFielddecoration 属性,它为您提供了很多可能性

Last but not least, you might want to have a look at the decoration property of you TextField, which gives you a lot of possibilities

如何更改 TextField

您可以使用 InputDecorationTextFielddecoration 属性.例如,您可以这样做:

You could play around with the InputDecoration and the decoration property of the TextField. For instance, you could do something like this:

TextField(                                
    decoration: const InputDecoration(
        contentPadding: const EdgeInsets.symmetric(vertical: 40.0),
    )
)

这篇关于如何更改 TextField 的高度和宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆