如何更改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]不为空,则文本范围的行高将为
[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
您可以使用TextField
的InputDecoration
和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屋!