[英]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.