当前位置:   article > 正文

flutter-Button_flutter开发elevatedbutton设置按钮颜色

flutter开发elevatedbutton设置按钮颜色

ElevatedButton

即"漂浮"按钮,它默认带有阴影和灰色背景。按下后,阴影会变大

圆角设置

  1. ElevatedButton(
  2. style: ButtonStyle(
  3. shape: MaterialStateProperty.all(RoundedRectangleBorder(
  4. borderRadius: BorderRadius.circular(20)))),
  5. onPressed: (() {}),
  6. child: Text("ElevatedButton"),
  7. )

边框颜色和宽度

  1. ElevatedButton(
  2. style: ButtonStyle(
  3. side: MaterialStateProperty.all(
  4. BorderSide(color: Colors.red,width: 4))),
  5. onPressed: (() {}),
  6. child: Text("ElevatedButton"),
  7. )


设置按钮背景

  1. ElevatedButton(
  2. style: ButtonStyle(
  3. backgroundColor: MaterialStateProperty.all(Colors.yellow)),
  4. onPressed: (() {}),
  5. child: Text("ElevatedButton"),
  6. )

设置按钮字体颜色

  1. ElevatedButton(
  2. style: ButtonStyle(
  3. foregroundColor: MaterialStateProperty.all(Colors.yellow)),
  4. onPressed: (() {}),
  5. child: Text("ElevatedButton"),
  6. )

指定按钮的宽高

  1. ElevatedButton(
  2. style: ButtonStyle(
  3. fixedSize:MaterialStateProperty.all(Size(200,300))),
  4. onPressed: (() {}),
  5. child: Text("ElevatedButton"),
  6. )

只指定宽

fixedSize:MaterialStateProperty.all(Size.fromWidth(200))),

只指定高

fixedSize:MaterialStateProperty.all(Size.fromHeight(300))),

minimumSize和maximumSize 显示按钮的最小或最大的尺寸,fixedSize任受它们的约束

  1. ElevatedButton(
  2. style: ButtonStyle(
  3. fixedSize:MaterialStateProperty.all(Size.fromWidth(300))
  4. ,maximumSize: MaterialStateProperty.all(Size.fromWidth(100))),
  5. onPressed: (() {}),
  6. child: Text("ElevatedButton"),
  7. )


最大宽度设置100,但实际宽度设置300,最终显示100的宽度 

设置按钮字体大小

  1. ElevatedButton(
  2. style: ButtonStyle(
  3. textStyle: MaterialStateProperty.all(TextStyle(fontSize: 30)),
  4. ),
  5. onPressed: (() {}),
  6. child: Text("ElevatedButton"),
  7. )

设置按钮内间距

在上面设置字体大小为30的前提下

  1. ElevatedButton(
  2. style: ButtonStyle(
  3. textStyle: MaterialStateProperty.all(TextStyle(fontSize: 30)),
  4. padding: MaterialStateProperty.all(EdgeInsets.all(30)),
  5. ),
  6. onPressed: (() {}),
  7. child: Text("ElevatedButton"),
  8. )

在指定宽度的前提下,设置按钮里面文字显示的位置

 按钮里文字右边居中显示:

  1. ElevatedButton(
  2. style: ButtonStyle(
  3. alignment:Alignment.centerRight,
  4. fixedSize: MaterialStateProperty.all(Size.fromWidth(300))
  5. ),
  6. onPressed: (() {}),
  7. child: Text("Button"),
  8. )

 按钮里文字左边居中显示:

  1. ElevatedButton(
  2. style: ButtonStyle(
  3. alignment:Alignment.centerLeft,
  4. fixedSize: MaterialStateProperty.all(Size.fromWidth(300))
  5. ),
  6. onPressed: (() {}),
  7. child: Text("Button"),
  8. )

  1. Alignment属性
  2. /// The top left corner.
  3. static const Alignment topLeft = Alignment(-1.0, -1.0);
  4. /// The center point along the top edge.
  5. static const Alignment topCenter = Alignment(0.0, -1.0);
  6. /// The top right corner.
  7. static const Alignment topRight = Alignment(1.0, -1.0);
  8. /// The center point along the left edge.
  9. static const Alignment centerLeft = Alignment(-1.0, 0.0);
  10. /// The center point, both horizontally and vertically.
  11. static const Alignment center = Alignment(0.0, 0.0);
  12. /// The center point along the right edge.
  13. static const Alignment centerRight = Alignment(1.0, 0.0);
  14. /// The bottom left corner.
  15. static const Alignment bottomLeft = Alignment(-1.0, 1.0);
  16. /// The center point along the bottom edge.
  17. static const Alignment bottomCenter = Alignment(0.0, 1.0);
  18. /// The bottom right corner.
  19. static const Alignment bottomRight = Alignment(1.0, 1.0);

阴影颜色,来点青青草原色

  1. ElevatedButton(
  2. style: ButtonStyle(
  3. shadowColor:MaterialStateProperty.all(Colors.green)
  4. ),
  5. onPressed: (() {}),
  6. child: Text("Button"),
  7. )


不是很明显

  • elevation    // 阴影值

  1. ElevatedButton(
  2. style: ButtonStyle(
  3. elevation : MaterialStateProperty.all(10),
  4. shadowColor:MaterialStateProperty.all(Colors.red)
  5. ),
  6. onPressed: (() {}),
  7. child: Text("Button"),
  8. )

现在明显多了

overlayColor 高亮色 按下时候的颜色

  1. ElevatedButton(
  2. style: ButtonStyle(
  3. overlayColor: MaterialStateProperty.all(Colors.red),
  4. ),
  5. onPressed: (() {}),
  6. child: Text("Button"),
  7. )


OutlinedButton 

  1. OutlinedButton(
  2. onPressed: (() {}),
  3. child: Text("OutlinedButton"),
  4. )

 TextButton

  1. TextButton(
  2. onPressed: (() {}),
  3. child: Text("TextButton"),
  4. )

附上官网地址:ButtonStyle class - material library - Dart API

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/302601
推荐阅读
相关标签
  

闽ICP备14008679号