I have notification menu icon. I need that to be animated when onCreateOptionsMenu()
called.
While implementing, i have been facing issue like below -
Attempt to invoke virtual method 'void
android.view.View.setAnimation(android.view.animation.Animation)' on a
null object reference.
Java code :
private Animation animation;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.home_screen,menu);
animation =
AnimationUtils.loadAnimation(getApplicationContext(),R.anim.notify);
menu.findItem(R.id.notifications).getActionView().setAnimation(animation);
return super.onCreateOptionsMenu(menu);
}
home_screen.xml :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/notifications"
android:title="@string/action_settings"
app:showAsAction="ifRoom"
android:icon="@drawable/notifications"/>
</menu>
notify.xml :
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="180"
android:pivotX="50%"
android:pivotY="50%"
android:duration="500"
android:interpolator="@android:anim/accelerate_interpolator" />
Kindly let me know the solution to resolve the issue. Thanks in advance.