如何在Xamarin.Forms中设置不同的图标 - android。
一个用于导航页面的应用程序,播放商店,用户屏幕等。
我更新了Project.Droid / MainActivity.cs文件:
[Activity(Label = "MyAppName", Icon = "MyIconName", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
但是这样改变了两个图标!!
我做的其他方式,我更新了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);
但是不起作用!!
任何想法???
答案 0 :(得分: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
文件夹:
它的外观: