[英]Flutter 2.0 - How to change Textbutton splash color when pressed
FlatButton is deprecated and shouldn't be used. Used TextButton instead.
在我以前的 FlatButton 小部件上,我能夠在按下時更改啟動顏色。 但是現在我正在使用 TextButton 小部件,我怎樣才能以有效的方式在MaterialApp ThemeData
上或直接在TextButton
小部件上更改它的顏色。
目前這是我的 TextButton
TextButton(
style: TextButton.styleFrom(
primary: Colors.red,
textStyle: TextStyle(
color: Colors.black45,
fontFamily: "Courier Prime",
),
backgroundColor: Colors.transparent,
),
onPressed: () {},
child: Text(
"Student",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
overlayColor is used to indicate that the button is focused, hovered, or pressed.
但我找不到這個overlayColor
首先請記住,TextButton 的主要屬性設置其文本和圖標的顏色。 它不會改變波紋顏色。 其次在 Textbutton 中沒有直接的屬性來改變啟動顏色。 因此,如果您想將初始顏色更改為透明,您可以這樣做。
TextButton(
style: ButtonStyle(
overlayColor: MaterialStateProperty.all(Colors.________),
),
)
TextButton(
style: ButtonStyle(
overlayColor: MaterialStateColor.resolveWith((states) => Colors.red),
),
child: ...,
)
您可以像這樣更改 Splash 顏色:
Theme(
data: ThemeData(
splashColor: Colors.red,
highlightColor: Colors.black.withOpacity(.5),
),
child: ListTile(
title: Text(
"New theme splash",
textAlign: TextAlign.center,
),
onTap: () {}),
),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.