[英]is there any way to make Text and Underline different colors in Flutter?
首先,您必须使用Material
小部件,并在其中定义RichText
、 TextSpan
和Text
。
在Material
小部件中,您需要设置下划线颜色。
Material(
child:RichText(),//input our need
);
您可以在 Text 属性中使用decorationColor: yourColor 来更改下划线的颜色。 例如,如果您想为所有文本加下划线:
Text("Your text",
style: TextStyle(
color: Colors.white
decoration: TextDecoration.underline,
decorationColor: Colors.yellow,
))
如果您只想在文本的一部分下划线,则必须将 RichText 与 TextSpan 结合使用。 例如:
RichText(
text: TextSpan(
children: [
TextSpan(
text: "NOT UNDERLINED TEXT",
style: TextStyle(
color: Colors.white)
),
TextSpan(
text: "UNDERLINED TEXT",
style: TextStyle(
color: Colors.white
decoration: TextDecoration.underline,
decorationThickness: 2,
decorationStyle: TextDecorationStyle.wavy))
],
style: TextStyle(color: Colors.yellow)
))
您可以使用RichText实现此行为。
RichText(
text: TextSpan(
text: 'You should only use this app when it is safe and legal to do so. ',
style: TextStyle(color: Colors.white),
children: [
TextSpan(
text: 'Please read our ',
style: TextStyle(
color: Colors.white,
),
children: [
TextSpan(
text: 'Privacy Policy',
style: TextStyle(
decoration: TextDecoration.underline,
decorationColor: Colors.yellow,
fontWeight: FontWeight.bold,
color: Colors.white,
),
)
],
),
],
),
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.