Use Spotlight.Builder to configure and launch a spotlight sequence. You can set multiple targets, a background color, duration, animation interpolator, and a container view. You can also attach an OnSpotlightListener to react to the spotlight starting or ending.
Note: If you want to show Spotlight immediately, ensure you wait until views are laid out using doOnPreDraw (from core-ktx).
val spotlight = Spotlight.Builder(this)
.setTargets(firstTarget, secondTarget, thirdTarget ...)
.setBackgroundColor(R.color.spotlightBackground)
.setDuration(1000L)
.setAnimation(DecelerateInterpolator(2f))
.setContainer(viewGroup)
.setOnSpotlightListener(object : OnSpotlightListener {
override fun onStarted() {
Toast.makeText(this@MainActivity, "spotlight is started", Toast.LENGTH_SHORT).show()
}
override fun onEnded() {
Toast.makeText(this@MainActivity, "spotlight is ended", Toast.LENGTH_SHORT).show()
}
})
.build()
// To show immediately after layout:
view.doOnPreDraw { Spotlight.Builder(this)...start() }