繁体   English   中英

如何更改 TextField 选择的颜色

[英]How to change the color of the TextField selection

如何更改文本字段“选择”的颜色,如下图所示:

例子

在此图像中,背景选择为蓝色,选项为灰色,但在颤动中,我该如何更改此颜色?

在您的ThemeData ,您可以选择TextSelectionTheme (最近的版本已迁移到此,如果您使用旧版本,则属性是ThemeData上的单个属性。 以下是它的文档和迁移文档中的示例:

ThemeData(
  textSelectionTheme: TextSelectionThemeData(
    cursorColor: Colors.red,
    selectionColor: Colors.green,
    selectionHandleColor: Colors.blue,
  )
)

编辑:如果您只想更改单个小部件的主题,您可以使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM