How to change text color of AppBar, icon color of FAB universally using theme?

后端 未结 9 1567
渐次进展
渐次进展 2020-12-14 13:50

I am able to set the background color of AppBar to Colors.amber. This automatically sets the text color to Black. I am aware of the accessibility i

相关标签:
9条回答
  • 2020-12-14 14:24

    You can set it with AppBarTheme

    theme: new ThemeData(
      textTheme: Theme.of(context).textTheme.apply(
        appBarTheme: AppBarTheme(
          textTheme: TextTheme(
            // center text style
            headline6: TextStyle(
              color: Colors.black
            ),
            // Side text style
            bodyText2: TextStyle(color: Colors.black)
          )
        )
      ),
    ),
    
    0 讨论(0)
  • 2020-12-14 14:27

    I used a slightly different technique, I didn't use a theme, I just customized its appearance, so that when I created it looked like this:

    appBar: new AppBar(
      iconTheme: IconThemeData(
        color: Colors.white
      ),
      title: const Text('Saved Suggestions', style: TextStyle(
        color: Colors.white
      )),
      backgroundColor: Colors.pink,
    ),
    
    0 讨论(0)
  • 2020-12-14 14:28

    title of AppBar uses headline6 and floatingActionBar uses color from primarySwatch. Though it is not documented in TextTheme, but I tested it. For example : to have red FloatingActionButton and blue title text in AppBar your theme inside MaterialApp should look like the following :

      MaterialApp(
        theme: ThemeData(
          primarySwatch: Colors.red,
          appBarTheme: AppBarTheme(            
            textTheme: TextTheme(
              headline6: TextStyle(
                color: Colors.blue,
                fontWeight: FontWeight.bold,
                fontSize: 28.0,
              ),
            ),
          ),
        ),
      )
    
    0 讨论(0)
  • 2020-12-14 14:34

    Easy and efficient and, less code method. Use light theme with desired color.

    theme: ThemeData.light().copyWith(
        accentColor: Colors.amber,
        primaryColor: Colors.amber,
    ),
    
    0 讨论(0)
  • 2020-12-14 14:36

    I think the most straightforward way of doing this is to adjust the title color for the theme that you are working with:

    theme: new ThemeData(
      primarySwatch: Colors.grey,
      primaryTextTheme: TextTheme(
        headline6: TextStyle(
          color: Colors.white
        )
      )
    )
    
    0 讨论(0)
  • 2020-12-14 14:39

    Firstly I wanna let u know that there are 3 ways to set colors in flutter.

    So u asked u wanna set color or text in app bar. So it works if u set color in style property of Text method. Let me show you how it works. And also I will show you 3 ways of setting color. It doesn't matter if u use theme property or not because setting color of Text works as diffrent. Thats way I didn't use Theme property in examples.

    1th:

    Scaffold(
      appBar: AppBar(
        title: Text("App Name",
        style: TextStyle(color: Colors.colorname),);
    

    2th :

    Scaffold(
      appBar: AppBar(
        title: Text("App Name",
        style: TextStyle(color: Color(0xffffff),));
    

    3th :

    Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        title: Text("App Name",
        style: TextStyle(color: Color.fromRGBO(0, 0, 0, 0, 0),));
    
    0 讨论(0)
提交回复
热议问题