Custom Loading Using Lottie Animation & Hilt

Today I will explain how to use Lottie as custom loading & how to make it easier to build using Hilt.

  • Add the file to the assets folder
  • We create a simple layout which will wrap the LottieAnimationView
  • Lottie’s setup is complete, now to use custom_loading.xml as custom loading I wrap the layout into an AlertDialog. And to make it easier to use on my activity / fragment, I will build the Hilt module
  • We use the AlertDialog on the activity / fragment we want

This is an example of the custom loading that I use

The things that must be considered in the Hilt module are :
1. You have to use ActivityContext if you use ApplicationContext you will get an error like this

error with application context

2. Use a custom qualifier otherwise the custom alert dialog will not run

That’s all I can say, hopefully it’s useful

if you want to see an example of the code, you can see it here

Thank you !
See you again

Always curious and always want to continue learning in many ways