- Use a
Toolbar. - Wait for the Toolbar to have its items inflated.
- Find the item in question
- Animate the item
Example:
mToolbar = (Toolbar) findViewById(R.id.toolbar); mToolbar.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { View item = mToolbar.findViewById(R.id.action_add_item); if (item != null) { mToolbar.removeOnLayoutChangeListener(this); item.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ObjectAnimator animator = ObjectAnimator .ofFloat(v, "rotation", v.getRotation() + 180); animator.start(); } }); } } });
Note R.id.action_add_item is the id attribute of the MenuItem.