[英]How to change color of border line in TextFormField with Flutter
[英]How to change TextFormField input text color in Flutter
在 uni 为 flutter 应用程序做 UI,我只希望在 TextFormField 中输入的文本是白色的。 这似乎是不必要的困难。 我试过谷歌搜索等,但看不到明显的答案。
new Theme(
// this colors the underline
data: theme.copyWith(
primaryColor: Colors.white,
hintColor: Colors.transparent,
),
child: new Padding(
padding: const EdgeInsets.fromLTRB(32.0, 40.0, 32.0, 4.0),
child: TextFormField(
key: Key('username'),
keyboardType: TextInputType.text,
controller: usernameController,
decoration: InputDecoration(
fillColor: Colors.black.withOpacity(0.6),
filled: true,
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(8.0),
),
borderSide: new BorderSide(
color: Colors.transparent,
width: 1.0,
),
),
labelText: 'Username',
labelStyle:
new TextStyle(color: Colors.white, fontSize: 16.0)),
style:
TextStyle(fontSize: 20.0, color: textTheme.button.color),
validator: validateUserName,
onSaved: (val) => this.loginFields._username = val),
),
),
这将:
TextFormField(
style: TextStyle(color: Colors.white),
)
Puedes 用户style: TextStyle
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
TextFormField(
TextFormField(
controller: field,
style: TextStyle(fontSize: 18, color: Colors.red),
decoration: const InputDecoration(
contentPadding: const EdgeInsets.only(
left: 15,
top: 8,
right: 15,
bottom: 0
),
hintText: 'name',
),
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
}
return null;
},
),
)
]
)
)
]
)
)
你可以用它来改变一切
TextFormField(
//controller: _phoneController,
cursorColor: Colors.black,
keyboardType: TextInputType.text,
style: TextStyle(
color: Colors.black
),
decoration: new InputDecoration(
hintStyle: TextStyle(
color: Colors.white
),
border: InputBorder.none,
//contentPadding:
//EdgeInsets.only(left: 15, bottom: 11, top: 11, right: 15),
hintText: "New Playlist"),
),
Padding(
padding: EdgeInsets.all(10),
child: TextFormField(
cursorColor: Color(0XFFFFCC00)//Cursor color change
style: TextStyle(
color: Color(0XFFFFCC00),
decorationColor: Color(0XFFFFCC00),//Font color change
backgroundColor: Color(0XFFFFCC00),//TextFormField title background color change
),
),
对于任何尝试从材质应用程序的theme: ThemeData
属性执行此操作的人,可以使用subtitle1
文本主题样式更改颜色。
MaterialApp(
...
theme: ThemeData(
...
textTheme: const TextTheme(
...
subtitle1: const TextStyle(
color: Colors.red, // <-- TextFormField input color
),
),
),
)
您正在更改此行中的输入文本颜色TextStyle(fontSize: 20.0, color: textTheme.button.color)
,因此为了设置为white
只需使用Colors.white
常量而不是textTheme.button.color
。
更多关于文本样式 在这里。
概述: textFormField 样式设置为定义为 MediumStyle 的 TextStyle。 样式会影响文本框中显示的字符。 而 labelStyle 会影响 inputdecoration 的字体显示。
TextFormField(
style: MediumStyle,
keyboardType: TextInputType.emailAddress,
focusNode: _employeeEmailFocus,
decoration: InputDecoration(labelText: "Employee Email", labelStyle:MediumBoldStyle),
validator: (val)=> null,
onSaved:(value)=> this._employeeEmail=value,
onFieldSubmitted: (term){
_fieldFocusChange(context,_employeeEmailFocus,_passwordFocus);
},
),
您可以在 TextFormField 中使用样式。
TextFormField(
style: const TextStyle(color: Colors.white),
),
装饰:const InputDecoration(labelStyle:TextStyle(颜色:Colors.white),),
如果您想使用 Global Change,请使用以下命令:
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
textTheme: Theme.of(context).textTheme.copyWith(
subtitle1: const TextStyle(color: Colors.green),
)),
home: const MyHomePage(),
);
否则你可以这样做:
TextFormField(
style: TextStyle(color: Colors.green),
)
为 textformfield 添加一个 inputdecoration 类,这是我认为的
decoration: InputDecoration(
prefixStyle: new TextStyle(
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.