【问题标题】:Change icon on Navigation bar - Xamarin.Forms Android更改导航栏上的图标 - Xamarin.Forms Android
【发布时间】:2016-08-19 21:58:32
【问题描述】:

如何在 Xamarin.Forms - android 中设置不同的图标。

一个用于应用程序、Play 商店、用户屏幕和其他用于导航页面。

我更新了 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);

但是不行!!

知道吗???

【问题讨论】:

    标签: c# xamarin xamarin.android xamarin.forms


    【解决方案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 文件夹:

    它的外观:

    【讨论】:

    • 如何在ios中做到这一点?
    猜你喜欢
    • 2018-08-15
    • 1970-01-01
    • 2016-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-24
    相关资源
    最近更新 更多