我正在构建 Xamarin.Forms 应用,我需要将导航栏的背景设置为图像。如果不创建 super 定制的东西,这可能吗?如果没有,最好的方法是什么?有没有其他人已经这样做了?
这是我需要做的。请注意带有后退按钮、消息图标和“评论”文本的导航栏区域。
有什么想法吗?
最佳答案
xamarin 无法更改导航背景图像。您必须针对每个平台以 native 方式执行此操作。
- 安卓:
在 Ressources/layout/Toolbar.axml 中删除背景颜色并添加:
android:background="@drawable/yourImage"
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});
- 图片
不要忘记将您的图像放在不同的资源文件夹中。
希望对您有所帮助!
关于c# - Xamarin.Forms:如何设置 NavigationPage 栏的背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44937501/