我正在尝试将对齐添加到文本字段中的提示文本。但它不起作用。如何把它带到中心?如何以曲线形状书写文字???
Container(
child: new TextFormField(
controller: _pass,
textAlign: TextAlign.center,
decoration: new InputDecoration.collapsed(
hintText: " PASSWORD", ), )),
Run Code Online (Sandbox Code Playgroud)
Ped*_*ina 10
我的问题是自动内容填充:
TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(0),
hintText: "hola mundo",
),
),
Run Code Online (Sandbox Code Playgroud)
快乐编码。
该textHint将有相同的对齐方式输入文本。所以你可以尝试下面的代码来实现你想要的:
TextFormField(
keyboardType: TextInputType.number,
maxLength: 5,
textAlign: TextAlign.center,
autofocus: true,
initialValue: '',
decoration: InputDecoration(
hintText: 'some hint',
counterText: "",
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(5.0)),
),
);
Run Code Online (Sandbox Code Playgroud)
小智 7
您可以将 textAlign: TextAlign.center 添加到您的代码中,这是我的代码及其工作原理:
new Padding(
padding: new EdgeInsets.all(30.0),
child:
new TextField(
textAlign: TextAlign.center,
decoration: new InputDecoration(
border: new OutlineInputBorder(
borderSide: new BorderSide(color: Colors.teal)),
hintText: 'REF: 2',
),
),
),
Run Code Online (Sandbox Code Playgroud)
注意:特定情况,但可能会帮助其他尝试过此线程中其他所有内容的人。
我有一个设计,我从中复制了所有的填充和对齐方式,但不知何故我无法将提示文本居中,它总是靠近顶部边缘几个像素。
唯一有效的是发现设计中设置了特定的文本高度。在我应用之后,一切都完美地对齐了。
InputDecoration(
hintStyle: TextStyle(
fontSize: _smallFontSize, // or whatever
height: 1.4, // <----- this was the key
),
// other properties...
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30602 次 |
| 最近记录: |