Xamarin.Forms:如何设置NavigationPage栏的背景图像 [英] Xamarin.Forms: how to set background image of NavigationPage bar
问题描述
我正在构建Xamarin.Forms应用程序,并且需要将导航栏的背景设置为图像.不创建超级自定义商品就可以吗?如果没有,那么最好的方法是什么?有人做过吗?
I'm building a Xamarin.Forms app and I need to set the background of the nav bars to an image. Is this possible without creating something super custom? If not, what's the best way to go about it? Has anyone else done it already?
这就是我需要做的.请注意导航栏区域,其中包含后退按钮,消息图标和"COMMENTARY"文本.
Here's what I need to do. Note the nav bar area with the back button, messaging icon, and "COMMENTARY" text.
有什么想法吗?
推荐答案
使用xamarin不能更改导航背景图像.您必须在每个平台的本机中执行此操作.
It's not possible with xamarin to change the navigation background image. You have to do that in native for each platform.
- Android:
在Ressources/layout/Toolbar.axml中删除背景色并添加:
in Ressources/layout/Toolbar.axml remove background color and add :
android:background="@drawable/yourImage"
2. iOS
在AppDelegate.cs中添加:
in AppDelegate.cs add :
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});
- 图片
别忘了将图像放在不同的资源文件夹中.
Don't forget to put your images in different ressources folders.
希望这对您有帮助!
这篇关于Xamarin.Forms:如何设置NavigationPage栏的背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!