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 :)

Cheers!

--

--

--

Passionate Android developer with tons left to learn. https://www.linkedin.com/in/miguellasa/

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

Recommended from Medium

Run a command in a running Android Emulator or Device

Android Code Coverage Metrics using Jacoco and SonarQube.

Practical Jetpack Compose: Get the beta!

Explicit API Mode Kotlin

Customer Support in PointPay Bank for Android

Best Practices for Custom Layouts in Push Notifications

Uploading images to AWS S3 with Flutter — Part 1

Android Lifecycle Scenarios — Single and Multi Activities

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. https://www.linkedin.com/in/miguellasa/

More from Medium

Building Successful Android Games on Google Play

How to check if an Android app is installed on your device

Automatic/One-Tap SMS Verification with the Google’s SMS Retriever API/ SMS User Consent API (Part…

Top 5 Android Games Sites In 2022