I'm making an Android app and I have a refresh button in my toolbar, defined in a menu like this :
<item
android:id="@+id/action_refresh"
android:icon="@drawable/ic_baseline_refresh_24"
android:title=""
app:showAsAction="always" />
and I'd like to start the rotation of it when the activity is created
I succeed in rotating it when touching it :
val view = findViewById<View>(R.id.action_refresh)
ObjectAnimator.ofFloat(view, "rotation", 360f).apply {
duration = 1000
repeatCount = Animation.INFINITE
interpolator = LinearInterpolator()
doOnCancel {
view?.rotation = 0f
}
}.start()
in onOptionsItemSelected
So i'd like to do the same thing in onCreateMenu, but I can't. I tested dozen of solutions from StackOverflow and nothing helps
EDIT:
It works if I set an app:actionViewClass on the menu item but I don't know what class to choose, it is a button like this