I'm trying to apply a 'pulse' animation to bring attention to menu items within my Toolbar; however, I cannot find a way to apply the animation to the overflow icon if all menu items are hidden.
Using the code from this solution, I can get the ActionMenuView, but it doesn't have any children to apply an animation to.
//amv.getChildCount() returns 0.
Within my Fragment
@Override
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
Toolbar toolbar = getToolbar();
for (int i = 0; i < toolbar.getChildCount(); i++) {
View view = toolbar.getChildAt(i);
if(view.getClass().getSimpleName().equals("ActionMenuView")) {
ActionMenuView amv = (ActionMenuView) view;
for (int i1 = 0; i1 < amv.getChildCount(); i1++) {
amv.getChildAt(i1).startAnimation((AnimationUtils.loadAnimation(getContext(),R.anim.pulse)));
}
}
}
menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:res="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/tutorial"
android:title="@string/tutorial"
res:showAsAction="never"
res:actionLayout="@layout/button_info_white"/>
<item
android:id="@+id/social_filter"
android:title="@string/social_filter"
res:showAsAction="never"
/>
</menu>
Thanks for your assistance.