Flutter 设置文字反选时的背景颜色

5 min read

在 Flutter 中,可以通过设置 TextField 的 decoration 属性来设置文字反选时的背景色。具体操作可以参考以下代码示例:

TextField(
  decoration: InputDecoration(
    filled: true,
    fillColor: Colors.grey[300], // 设置背景色为灰色
  ),
),

在上述代码中,通过设置 filled 属性为 true 来启用 TextField 的填充背景功能;然后通过设置 fillColor 属性来指定反选文本的背景色。

需要注意的是,如果在 Flutter 中使用自定义文本编辑器,需要在编辑器的属性中设置指定的反选背景色。