[英]How to change the color of the TextField selection
In your ThemeData
, you have the option for a TextSelectionTheme
(recent versions have migrated to this, if you are using an older version the properties are individual properties on ThemeData
. Here are the docs for it and an example from the migration docs :在您的
ThemeData
,您可以选择TextSelectionTheme
(最近的版本已迁移到此,如果您使用旧版本,则属性是ThemeData
上的单个属性。 以下是它的文档和迁移文档中的示例:
ThemeData(
textSelectionTheme: TextSelectionThemeData(
cursorColor: Colors.red,
selectionColor: Colors.green,
selectionHandleColor: Colors.blue,
)
)
EDIT: If you just want to change a single widget's theme, you can wrap your build function with the Theme
widget like this:编辑:如果您只想更改单个小部件的主题,您可以使用
Theme
小部件包装您的构建功能,如下所示:
Widget build(BuildContext context) {
return Theme(
child: MyWidget(),
data: ThemeData(
textSelectionTheme: TextSelectionThemeData(
cursorColor: Colors.red,
selectionColor: Colors.green,
selectionHandleColor: Colors.blue,
)));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.