2016-08-19 22 views
1

Xamarin.Forms - Androidでさまざまなアイコンを設定する方法を教えてください。ナビゲーションバーのアイコンを変更する - Xamarin.Forms Android

ナビゲーションページのアプリケーション、プレイストア、ユーザー画面などのためのものです。

私はProject.Droid/MainActivity.csファイル更新:

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

しかし、この方法の変更の2つのアイコンを!!

私は、私はProjectForms/App.cs更新でしたその他の方法:

 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); 

しかし、動作しませんが!

答えて

1

カスタムレンダラでそれを行うことができます:

enter image description here

それはどのようになりますルックス:

enter image description here

+0

優れ

[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フォルダにアイコンを追加します。これは正しい方法です。どうもありがとう!!!! – hagnr

+0

iosでこれを行う方法は? –

関連する問題