简体   繁体   English

如何在 Flutter 中更改文本的颜色

[英]How can you change to color of the text in Flutter

So, Im new to flutter and wanted to see how can you change the color of the text.所以,我是新手,想看看如何改变文本的颜色。

import 'package:flutter/material.dart';

void main() => runApp(new Hello());

class Hello extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Material(
        child: new Center(
          child: new Text("Hello!"),
        ),
      ),
    );
  }
}

this is a basic hello text and I want the text to be other color than the standard.这是一个基本的问候文本,我希望文本是标准颜色以外的其他颜色。

This can be easily achieved by style function.这可以通过样式函数轻松实现。 Which will take the TextStyle parameter, where you can specify color.这将采用TextStyle参数,您可以在其中指定颜色。 You can use a Material set of colors, like red, yellow, green, blue, black, transparent, etc. Or you can specify by its HEX color code, like this: TextStyle(color: Color(0xff**000000**)) .您可以使用一组 Material 颜色,如红色、黄色、绿色、蓝色、黑色、透明等。或者您可以通过其十六进制颜色代码指定,如下所示: TextStyle(color: Color(0xff**000000**)) The HEX color always starts with 0xff followed by the six-digit number of the color. HEX 颜色始终以0xff开头,后跟颜色的六位数字。

import 'package:flutter/material.dart';

void main() => runApp(new Hello());

class Hello extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Material(
        child: new Center(
          child: new Text("Hello!", style: TextStyle(color: Colors.indigo)),
        ),
      ),
    );
  }
}

Also, with material colors you can give them different shades by specifying their opacity, like TextStyle(color: Colors.green[600])此外,对于材质颜色,您可以通过指定它们的不透明度来赋予它们不同的色调,例如TextStyle(color: Colors.green[600])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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