Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更改导航栏上的图标-Xamarin.Forms Android_C#_Xamarin_Xamarin.android_Xamarin.forms - Fatal编程技术网

C# 更改导航栏上的图标-Xamarin.Forms Android

C# 更改导航栏上的图标-Xamarin.Forms Android,c#,xamarin,xamarin.android,xamarin.forms,C#,Xamarin,Xamarin.android,Xamarin.forms,如何在Xamarin.Forms-android中设置不同的图标 一个用于应用程序、播放商店、用户屏幕,另一个用于导航页面 我更新了Project.Droid/MainActivity.cs文件: [Activity(Label = "MyAppName", Icon = "MyIconName", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]

如何在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);
但是不起作用


有什么想法吗

您可以使用自定义渲染器:

[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);
        }
    }
}
[程序集:ExportRenderer(typeof(NavigationPage)、typeof(NavigationPageRenderer))]
命名空间SuperForms.Samples.Droid
{
公共类NavigationPageRenderer:NavigationRenderer
{
受保护的覆盖无效OnElementChanged(ElementChangedEventArgs e)
{
基础。一个要素发生变化(e);
var actionBar=((活动)上下文);
actionBar.SetIcon(Resource.Drawable.newIcon);
}
}
}
将图标添加到
Resources/drawable
文件夹:

它的外观:


如何在ios中执行此操作?