Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Floating action button: how to change the splash color and highlight color like in a RaisedButton?

I see that the splash and highlight colors that the FAB takes are connected to argument color in the MaterialApp widget. is there a way to override those colors? I found only foreground color and background colors and those are not what I want. Thanks

like image 903
Floris Marpepa Avatar asked Feb 09 '19 17:02

Floris Marpepa


People also ask

How do you color a floating action button?

To change background color of Floating Action Button in Kotlin Android, set the backgroundTint attribute (in layout file) or backgroundTintList property (in Kotlin file) of FAB with the required color.

How do you style a floating action button?

Add the floating action button to your layoutThe size of the FAB, using the app:fabSize attribute or the setSize() method. The ripple color of the FAB, using the app:rippleColor attribute or the setRippleColor() method. The FAB icon, using the android:src attribute or the setImageDrawable() method.


1 Answers

If you check the source code of FloatingActionButton the splash color is tied to the Theme of the app, so you can change the theme only for the button, like this:

Theme(
  data: Theme.of(context).copyWith(highlightColor: Colors.yellow),
  child: FloatingActionButton(
    backgroundColor: Colors.red,
    onPressed: () {},
    child: Text("hello world"),
 ),
)
like image 191
diegoveloper Avatar answered Oct 19 '22 21:10

diegoveloper