【问题标题】:How to change Xamarin back button in menu bar?如何更改菜单栏中的 Xamarin 后退按钮?
【发布时间】:2015-05-30 02:29:29
【问题描述】:

这就是我所拥有的:

这是我想要的:

如果导航堆栈中没有页面,则标题图标将在左角,否则将有返回箭头和“返回”文本。 我没有找到任何自定义选项,有可能吗?

【问题讨论】:

    标签: c# xamarin menubar xamarin-forms


    【解决方案1】:

    如果您在 NavigationPage 中使用 MasterPage,则可以将箭头更改为汉堡图标:

    Detail = new NavigationPage(masterPage);
    

    如果您想隐藏图标 - 它仅适用于 Android。可以通过自定义渲染器解决(http://developer.xamarin.com/guides/cross-platform/xamarin-forms/custom-renderer/):

    [assembly:ExportRenderer (typeof(NavigationPage), typeof(CustomNavigationRenderer ))]
    public class CustomNavigationRenderer : NavigationRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e)
        {
            base.OnElementChanged (e);
    
            var actionBar = ((Activity)Context).ActionBar;
            actionBar.SetIcon (Resource.Color.Transparent);
        }
    }
    

    要更改图标,只需更改项目文件:

    • YourProject/Resources/drawable/icon.png
    • YourProject/Resources/drawable-hdpi/icon.png
    • YourProject/Resources/drawable-xhdpi/icon.png
    • YourProject/Resources/drawable-xxhdpi/icon.png

    或在您的MasterDetailPage 上将Icon 属性设置为另一个资源。

    【讨论】:

      【解决方案2】:

      在 NavigationPage 对象上使用静态方法 SetTitleIcon。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-04-29
        • 1970-01-01
        • 2017-09-21
        • 2016-10-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多