How to change Xamarin back button in menu bar?

十年热恋 提交于 2019-12-22 10:56:36

问题


this is what I have:

this is what I want to get:

If there is no pages in navigation stack, then title icon will be in left corner, else there will be back arrow and "Back" text. I didn't find any options to customize it, is it possible at all?


回答1:


You can change arrow to hamburger icon if you use your MasterPage within NavigationPage:

Detail = new NavigationPage(masterPage);

If you want to hide icon - it only applies to Android. It can be solved with custom renderer (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);
    }
}

To change icon, just change project files:

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

or on your MasterDetailPage set Icon property to another resource.




回答2:


use the static method SetTitleIcon on the NavigationPage object.



来源:https://stackoverflow.com/questions/30541603/how-to-change-xamarin-back-button-in-menu-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!