如何在菜单栏中更改Xamarin后退按钮? [英] How to change Xamarin back button in menu bar?
问题描述
这就是我所拥有的:
这就是我想要得到的:
如果导航堆栈中没有页面,则标题图标将在左上角,否则将有后退箭头和后退"文本. 我没有找到用于自定义它的任何选项,这有可能吗?
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?
推荐答案
如果您在NavigationPage中使用MasterPage
,则可以将箭头更改为汉堡包图标:
You can change arrow to hamburger icon if you use your MasterPage
within NavigationPage:
Detail = new NavigationPage(masterPage);
如果要隐藏图标-它仅适用于Android.可以使用自定义渲染器解决此问题( http://developer. xamarin.com/guides/cross-platform/xamarin-forms/custom-renderer/):
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
或在您的MasterDetailPage
上将Icon
属性设置为另一资源.
or on your MasterDetailPage
set Icon
property to another resource.
这篇关于如何在菜单栏中更改Xamarin后退按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!