2017-11-04 18 views
0

일부 로직으로 메뉴 항목에 애니메이션을 적용하려고하지만 refresh의 ID가있는 메뉴 항목이 ActionView 속성에 null로 표시됩니다. 내가 뭘 잘못 했니?Android 메뉴 항목의 ActionView 속성은 항상 null입니다.

메뉴 항목 XML을 :

<?xml version="1.0" encoding="utf-8" ?> 
    <menu xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:local="http://schemas.android.com/apk/res-auto"> 
     <item 
      android:id="@+id/refresh" 
      android:icon="@drawable/plus_white" 
      local:showAsAction="ifRoom" 
      local:actionViewClass="android.support.v7.widget.ImageView" 
      android:title="Refresh" /> 
     <item 
      android:id="@+id/favoritePodcast" 
      android:icon="@drawable/favorite_star" 
      local:showAsAction="ifRoom" 
      android:title="Favorite" /> 

    </menu> 

OnCreateOption ::

 public override bool OnCreateOptionsMenu(IMenu menu) 
      { 
       MenuInflater.Inflate(Resource.Menu.MainMenu, menu); 

       if (_notified) 
       { 
        IMenuItem item = menu.FindItem(Resource.Id.refresh); 
        var itemView= item.ActionView.JavaCast<Android.Widget.ImageView>(); 

        Animation anim = AnimationUtils.LoadAnimation(ApplicationContext, 
                 Resource.Animation.fade_in); 

        itemView.StartAnimation(anim); 
        Toast.MakeText(this, "Notified", ToastLength.Short).Show(); 
       } 

       return base.OnCreateOptionsMenu(menu); 
      } 

중단 점보기 : 나는 대답을 발견

답변

0

. https://forums.xamarin.com/profile/355640/robbit 내가 같은 메뉴 항목에 대한 새로운 레이아웃을 정의 :

NewItemRefresh.axml : 덕분에 도움을 robbit하는 >>>>

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="48dp" 
    android:layout_height="fill_parent" 
    android:layout_gravity="right" > 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:clickable="true" 
     android:src="@drawable/plus_white"/> 

</RelativeLayout> 

및 안드로이드 추가 : actionLayout = "@ 레이아웃/NewItemRefresh을

<?xml version="1.0" encoding="utf-8" ?> 
    <menu xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:local="http://schemas.android.com/apk/res-auto"> 
     <item 
      android:id="@+id/refresh" 
      android:icon="@drawable/plus_white" 
      local:showAsAction="ifRoom" 
      local:actionViewClass="android.support.v7.widget.ImageView" 
      android:actionLayout="@layout/NewItemRefresh" 
      android:title="Refresh" /> 
     <item 
      android:id="@+id/favoritePodcast" 
      android:icon="@drawable/favorite_star" 
      local:showAsAction="ifRoom" 
      android:title="Favorite" /> 

    </menu> 

과의 onCreateOptionsMenu : "이제 메뉴 항목

에 메뉴 항목이 변경

 public override bool OnCreateOptionsMenu(IMenu menu) 
      { 
       MenuInflater.Inflate(Resource.Menu.MainMenu, menu); 

       if (_notified) 
       { 
        IMenuItem item = menu.FindItem(Resource.Id.refresh); 
        View view = LayoutInflater.Inflate(Resource.Layout.NewItemRefresh, null); 
        item.SetActionView(view); 
        var itemView= item.ActionView.JavaCast<Android.Widget.RelativeLayout>(); 

        Animation anim = AnimationUtils.LoadAnimation(ApplicationContext, 
                 Resource.Animation.fade_in); 

        itemView.StartAnimation(anim); 
        Toast.MakeText(this, "Notified", ToastLength.Short).Show(); 
       } 

       return base.OnCreateOptionsMenu(menu); 
      } 

그래서 어떤 논리로 메뉴 항목을 움직일 수 있습니다.