Android changing Floating Action Button color
Ambush your Floating Action Button's appearance! Use the trusty setBackgroundTintList method:
Just replace R.color.newColor
with whatever color you fancy in colors.xml
.
Let's get practical: XML customization
Material Design says no square FABs! So, avoid android:background
as it will transfigure your FAB into a sad square. Instead, pimp your FAB by:
For those who like to live on the edge, or rather without edges, set app:borderWidth
to 0dp
:
Be that cool dev who keeps the ripple effect alive:
But remember, compatibility is your best friend.
Does your FAB feel flat? Give it a lift with a subtle shadow:
Playing with Code: Change in action
Icons need to be fashion-forward too. Dress them up in vibrant colors. Remember to consult the Design Library Fashion Manual for the rules:
or
Feeling adventurous? Get dynamic with ColorStateList
.
Got pre-Lollipop devices? They'll swap ripple animations for a colorful shapeshift when pressed.
Dealing with “the other stuff”
Transparencies
For that transparent look, use:
Ripples
Post 22.2.1 versions of the Material Design Library allow color control over the ripple effect.
Just remember to convert your color to the expected integer format.
Was this article helpful?