如何更改 TextField 的高度和宽度? [英] How to change TextField's height and width?
问题描述
如何自定义TextField
的width
和height
?
推荐答案
要调整宽度,您可以用 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.
最后但同样重要的是,您可能想看看 TextField
的 decoration
属性,它为您提供了很多可能性
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
您可以使用 InputDecoration
和 TextField
的 decoration
属性.例如,您可以这样做:
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屋!