2016-08-19 2 views
1

Xamarin.Forms - Android에서 어떻게 다른 아이콘을 설정할 수 있습니까?탐색 모음의 아이콘 변경 - Xamarin.Forms Android

네비게이션 페이지의 애플리케이션, 플레이 스토어, 사용자 화면 및 기타 용.

내가 업데이트 Project.Droid/MainActivity.cs 파일 :

[Activity(Label = "MyAppName", Icon = "MyIconName", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] 

그러나이 방법 변경이 개 아이콘!

 Current.Resources = new ResourceDictionary(); 
     Current.Resources.Add("UlycesColor", Color.FromRgb(121, 248, 81)); 
     var navigationStyle = new Style(typeof(NavigationPage)); 
     var barTextColorSetter = new Setter { Property = NavigationPage.BarTextColorProperty, Value = Color.Black }; 
     var barBackgroundColorSetter = new Setter { Property = NavigationPage.BarBackgroundColorProperty, Value = Color.White }; 
     var barIcon = new Setter { Property = NavigationPage.IconProperty, Value = "newIcon.png" }; 

     navigationStyle.Setters.Add(barTextColorSetter); 
     navigationStyle.Setters.Add(barBackgroundColorSetter); 
     navigationStyle.Setters.Add(barIcon); 
     Current.Resources.Add(navigationStyle); 

을하지만 작동하지 않습니다! :

다른 방법으로 내가 한 그, 나는 ProjectForms/App.cs 업데이트

어떤 아이디어 ???

답변

1

사용자 정의 렌더러와 함께 할 수 있습니다 :

[assembly:ExportRenderer (typeof(NavigationPage), typeof(NavigationPageRenderer))] 
namespace SuperForms.Samples.Droid 
{ 
    public class NavigationPageRenderer : NavigationRenderer 
    { 
     protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e) 
     { 
      base.OnElementChanged(e); 

      var actionBar = ((Activity)Context).ActionBar; 
      actionBar.SetIcon(Resource.Drawable.newIcon); 
     } 
    } 
} 

추가 아이콘 Resources/drawable 폴더에 :

enter image description here

가 어떻게이 보이는 것입니다 : 우수한

enter image description here

+0

합니다. 이것이 올바른 방법입니다. 고마워요 !!!! – hagnr

+0

ios에서이 작업을 수행하는 방법은 무엇입니까? –