简体   繁体   中英

Flutter change Textfield selected background color

I have a TextField which looks like this at the moment:

在此处输入图像描述

As you can see the selected color is purple. But how can I change that color for that specific TextField ? I do not want to change the AppThemeData . I couldn't find anything on this... Happy for every help!

you can try and wrap it with Theme and use SplashColor to be something like this:

Theme(
  data: ThemeData(textSelectionColor: Colors.green),
  child: TextField(
    autofocus: false,
    decoration: InputDecoration(
      filled: true,
      fillColor: Colors.white,
      hintText: 'Mail',
     
    ),
  ),
);

or do this in main:

theme: ThemeData(
          accentColor: Color(0xffBA379B).withOpacity(.6),
          primaryColor: Color(0xffBA379B),
          textSelectionTheme: TextSelectionThemeData(
            selectionColor: Color(0xffBA379B).withOpacity(.5),
            cursorColor: Color(0xffBA379B).withOpacity(.6),
            selectionHandleColor: Color(0xffBA379B).withOpacity(1),
          ),
    ```

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.

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