简体   繁体   中英

How modify the highlight color of TextField when tapped ? (Flutter)

I am trying to change my labelText color when focused. I can change the text color but not when focused. In the screenshots below, the string "Email" remains blue when focused.

This is what I have:

Container(
  margin: EdgeInsets.symmetric(horizontal: 600),
  child: TextField(
    decoration: InputDecoration(
      border: UnderlineInputBorder(),
      labelText: 'Email',
      suffix: Icon(
        Icons.check,
      ),
    ),
  ),
),
                  

This is what the button looks like before it's pressed.

在此处输入图像描述

When it's pressed, it looks like this

在此处输入图像描述

How can I modify these highlights to be black instead of light blue? Thanks!

Try to change your inputDecoration labelStyle:

InputDecorationTheme(
      labelStyle: TextStyle(
    color: black,
    fontSize: 12,
  );

There are 2 ways you can modify the TextField's highlight color:

  1. Use InputDecoration (do this if you want to locally modify a single TextField )
Container(
  child: TextField(
    decoration: InputDecoration(
      focusedBorder: UnderlineInputBorder(
        borderSide: BorderSide(color: Colors.black),
      ),
      labelText: 'Email',
      labelStyle: TextStyle(color: Colors.black),
      suffix: Icon(
        Icons.check,
      ),
    ),
  ),
)
  1. Config the theme property of the MaterialApp widget (do this if you want to set a common theme across all TextField widgets):
MaterialApp(
      theme: ThemeData(
          inputDecorationTheme: InputDecorationTheme(
        focusedBorder:
            UnderlineInputBorder(borderSide: BorderSide(color: Colors.black)),
        labelStyle: TextStyle(color: Colors.black),
      ),
   ),
   home: SomeScreen(),
);

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