I would use the BadgeDrawable
in my Android app on a Button
, the issue is that when i'm trying to set to the button layout the badgeDrawable
via attachBadgeDrawable
i get an error on it which says:
his declaration is opt-in and its usage should be marked with '@com.google.android.material.badge.ExperimentalBadgeUtils' or '@OptIn(markerClass = com.google.android.material.badge.ExperimentalBadgeUtils.class)'
The code where i use that piece of code is the following:
btnInvia.viewTreeObserver.addOnGlobalLayoutListener(
object : OnGlobalLayoutListener {
override fun onGlobalLayout() {
val badgeDrawable = BadgeDrawable.create(requireContext())
badgeDrawable.number = corpo
badgeDrawable.verticalOffset = 20
badgeDrawable.horizontalOffset = 15
BadgeUtils.attachBadgeDrawable(badgeDrawable, btnInvia, layoutInvia)
btnInvia.viewTreeObserver.removeOnGlobalLayoutListener(this)
}
}
)
if it could be usefull the min SDK is 24.