Lightning Round: Android Gradient Floating Action Button

The purpose of this, and other Lighting Round articles, is to share a small, but possibly useful, piece of information/code/concept that could be of some help, and hopefully, even save you some time. You’ll be done before The Flash has a chance to change the timeline!

So everybody loves a FAB, right? And gradients seem to be everywhere nowadays, correct? So it was just a matter of time before someone needed a FAB with a gradient background.

I tried a couple of approaches I read here and there, but honestly, either I couldn’t make them work, or just didn’t like them. Finally, I came across this other way of doing it which I’ll show you here. I was a little skeptical at first, but I was more than satisfied with the end result.

Here’s the code (notice the size is defined via the style, not the layout, just cause).

Paste this in any layout to try it out
The default FAB size is 56dp, and 40dp for mini
This will make the ImageButton look real nice

And here’s what you get:

Pretty, right?

That’s it. This has worked for me every single time, and I like it. If you know of a better way, please, leave a comment below so we can all benefit from that knowledge :)





Passionate Android developer with tons left to learn.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Implementing your first Android lint rule

Android — Bitbucket — Pipeline — CI/CD with Firebase App Distribution

Useful Kotlin Extensions for Android

CI/CD Pipeline for Flavoured Android Apps using Fastlane and Github Actions

Google Fit with fit_kit package!

Beginner: Integration of Huawei Accelerate Kit in kotlin (Android)

Top Announcement About Flutter 3.0

Decrease memory usage of your Android app in half

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Miguel Lasa

Miguel Lasa

Passionate Android developer with tons left to learn.

More from Medium

Android Intents and Single Login Per Class— Kotlin

Network Data Transfer Using Volley Library— Android

OxygenOS 12 for OnePlus 9 and 9 Pro is rolling out once more, hopefully fixes all the issues…

Do AppAuth Android Step By Step