Text selection color can be changed by globally setting the theme:
theme: ThemeData.light().copyWith(
accentColor: kPrimaryAccent,
primaryColor: kPrimaryColor,
textSelectionColor: kTextSelectionColor,
textSelectionHandleColor: kPrimaryAccent)
But how can this be done locally in a single text-field?
You can wrap your widget with a Theme
and set the textSelectionColor
for its ThemeData
:
Container(
child: Theme(
data: ThemeData(
textSelectionColor: Colors.yellow,
),
child: SelectableText(
'this is a text',
),
),
),
You have multiple choices to do so here is some example:
TextStyle
Text(
"Test Text",
style: TextStyle(
color: Color(// Hex color)
),
)
Theme
Theme(
data: Theme.of(context).copyWith(// new ThemeData here),
child: Text("Test Text"),
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.