如何在 Flutter 中的 EditText 上更改气泡(光标下)的颜色

Hai*_*sen 5 dart flutter

如何更改在 Text 或 TextFormField 或 .. 在 Flutter 中选择文本时出现的气泡颜色?

是相同的问题,但针对本机代码。

Dar*_*ish 8

您可以使用textSelectionHandleColor属性。

Theme(
          data: Theme.of(context).copyWith(
            textSelectionHandleColor: Colors.green, 
          ),
          child: TextField(),
        );
Run Code Online (Sandbox Code Playgroud)


Kun*_*hra 6

根据this flutter documentationtextSelectionHandleColor已弃用。您应该像下面的代码一样selectionHandleColorTextSelectionThemeData小部件内使用。

  theme: ThemeData(
   
    textSelectionTheme: TextSelectionThemeData(
      cursorColor: Colors.red,
      selectionColor: Colors.green,
      selectionHandleColor: Colors.black,
    ),
  )
Run Code Online (Sandbox Code Playgroud)