Flutter 如何在Flatter中更改文本字段的内部颜色?
我想更改Flitter中文本字段的颜色。 指输入边界内的区域。 我试图将文本字段包装到容器中,并更改容器的颜色,但这似乎是解决问题的愚蠢步骤 我尝试了fillColor选项,但没有任何改变 这是我的代码-->Flutter 如何在Flatter中更改文本字段的内部颜色?,flutter,textfield,Flutter,Textfield,我想更改Flitter中文本字段的颜色。 指输入边界内的区域。 我试图将文本字段包装到容器中,并更改容器的颜色,但这似乎是解决问题的愚蠢步骤 我尝试了fillColor选项,但没有任何改变 这是我的代码--> 提前感谢:)试试这个:- 装饰:输入装饰( 是的, 填充颜色:颜色。灰色, 如果要将颜色设置为文本字段,则需要将一个布尔变量设置为true,以便将颜色添加到文本字段中 Container( child: TextField(
提前感谢:)
试试这个:-
装饰:输入装饰(
是的,
填充颜色:颜色。灰色,
如果要将颜色设置为文本字段,则需要将一个布尔变量设置为true,以便将颜色添加到文本字段中
Container(
child: TextField(
cursorColor: Color(0xFF7675E0),
textAlign: TextAlign.left,
decoration: InputDecoration(
fillColor: Colors.black, // you can change color of textfield
filled: true, // this should be true if you want to set color to textfield
hintText: "Search",
prefixIcon: Icon(Icons.search),
),
),
),
基本上你可以留下你提供给我们的代码
filled: true
应用此值后,可以轻松设置背景色的样式。
参考文档:不要使用容器装饰文本字段,文本字段中有更多属性 文本字段使用
decoration: InputDecoration(
filled: true,
fillColor: Colors.white10,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.all(
new Radius.circular(14.0),
),
),
在填充颜色语句之前添加
filled:true,
。
decoration: InputDecoration(
filled: true,
fillColor: Colors.white10,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.all(
new Radius.circular(14.0),
),
),
TextField(
controller: usernameController,
keyboardType: TextInputType.emailAddress,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
filled: true,
fillColor: Colors.white10,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.all(
new Radius.circular(14.0),
),
),
hintText: 'Username',
hintStyle: TextStyle(color: Colors.white),
contentPadding: const EdgeInsets.all(24),
prefixIcon: Icon(Icons.person, color: Colors.white),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white10),
borderRadius: BorderRadius.circular(14),
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white10),
borderRadius: BorderRadius.circular(14),
),
),
),