Xamarin.Forms:如何设置NavigationPage栏的背景图像

Jon*_*han 2 c# user-interface xamarin xamarin.forms

我正在构建Xamarin.Forms应用,并且需要将导航栏的背景设置为图像。不创建超级自定义商品就可以吗?如果不是,最好的方法是什么?有人做过吗?

这是我需要做的。请注意带有后退按钮,消息图标和“ COMMENTARY”文本的导航栏区域。

在此处输入图片说明

有任何想法吗?

the*_*ouk 5

使用xamarin不可能更改导航背景图像。对于每个平台,您都必须使用本机。

  1. 安卓:

在Ressources / layout / Toolbar.axml中删除背景色并添加:

android:background="@drawable/yourImage"
Run Code Online (Sandbox Code Playgroud)

2. iOS

在AppDelegate.cs中添加:

UINavigationBar.Appearance.BarTintColor=UIColor.FromPatternImage(UIImage.FromFile("YOURIMAGE.png"));
// To change Text Colors to white here
UINavigationBar.Appearance.TintColor=UIColor.White;
// To change Title Text colors to white here
UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes() { TextColor = UIColor.White});
Run Code Online (Sandbox Code Playgroud)
  1. 图片

不要忘记将图像放在不同的资源文件夹中。

希望这对您有所帮助!

  • iOS的答案已过期-您可以执行UINavigationBar.Appearance.SetBackgroundImage(UIImage.FromFile(“ YOURIMAGE.png”),UIBarMetrics.Default);` (3认同)