android - Can't get Actionbar Icon to animate -


i'm trying refresh button on actionbar rotate, i'm having trouble getting work. view seems lose it's horziontal margin/padding (which haven't set anywhere), , not rotate. no null errors, crashes, or else point me in right direction. doing wrong? apreciated.

main.java:

public class main extends actionbaractivity{  ...      @override     public boolean onoptionsitemselected(menuitem item) {          switch (item.getitemid()) {             case r.id.action_refresh:                 refresh();                 break;             default:                 break;         }         return super.onoptionsitemselected(item);     }       public void refresh() {          layoutinflater inflater = (layoutinflater) this.getsystemservice(context.layout_inflater_service);         imageview imageview = (imageview) inflater.inflate(r.layout.action_refresh, null);          animation rotation = animationutils.loadanimation(this, r.anim.rotate);         rotation.setrepeatcount(animation.infinite);         imageview.startanimation(rotation);          menuitem item = menu.finditem(r.id.action_refresh);         item.setactionview(r.layout.action_refresh);     } } 

menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"       xmlns:yourapp="http://schemas.android.com/apk/res-auto" >      <item android:id="@+id/action_refresh"           android:icon="@drawable/ic_action_refresh"           android:title="refresh"           android:actionlayout="@layout/action_refresh"           yourapp:showasaction="ifroom"           />      <item           android:id="@+id/category_spinner_item"           android:showasaction="ifroom"           android:actionlayout="@layout/action_sort"           /> </menu> 

action_refresh.xml

<?xml version="1.0" encoding="utf-8"?>  <imageview xmlns:android="http://schemas.android.com/apk/res/android"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:src="@drawable/ic_action_refresh"            /> 

anim/rotate.xml

<rotate xmlns:android="http://schemas.android.com/apk/res/android"         android:fromdegrees="0"         android:todegrees="360"         android:pivotx="50%"         android:pivoty="50%"         android:duration="10000"         android:interpolator="@android:anim/linear_interpolator" /> 

just change line:

item.setactionview(r.layout.action_refresh); 

to this:

menuitemcompat.setactionview(item, imageview); 

the reason doesn't animate original line because setting action view static image resource, not imageview set animate.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -