我有通知菜单图标。我需要在onCreateOptionsMenu()
调用时对其进行动画处理。
在实施过程中,我一直面临如下问题-
Attempt to invoke virtual method 'void
android.view.View.setAnimation(android.view.animation.Animation)' on a
null object reference.
Java代码:
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" />
请让我知道解决该问题的解决方案。 预先感谢。