繁体   English   中英

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

[英]Xamarin.Forms: how to set background image of NavigationPage bar

我正在构建 Xamarin.Forms 应用程序,我需要将导航栏的背景设置为图像。 如果不创建超级定制的东西,这可能吗? 如果没有,最好的方法是什么? 有没有其他人已经这样做了?

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

在此处输入图像描述

有任何想法吗?

xamarin 无法更改导航背景图像。 您必须针对每个平台以本机方式执行此操作。

  1. 安卓:

在 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});
  1. 图片

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

希望这对你有帮助!

您可以向导航栏添加背景图像和按钮。 element 可用于自定义元素。 您可以使用 AbsoluteLayout 来实现您想要的(按钮、文本等)

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:d="http://xamarin.com/schemas/2014/forms/design"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                 mc:Ignorable="d"                 
                 x:Class="MobileApp.Views.PhotoUploadPage">
   <NavigationPage.TitleView>
        <StackLayout>
            <Image Source="background_image.jpg"></Image>
        </StackLayout>
   </NavigationPage.TitleView>
   <ContentPage.Content>
           <StackLayout>
                <Label Text="Welcome to Multiple Photo Upload!"
                   VerticalOptions="CenterAndExpand" 
                   HorizontalOptions="CenterAndExpand" />
           </StackLayout>
   </ContentPage.Content>
</ContentPage>

https://forums.xamarin.com/discussion/139894/putting-an-image-on-navigation-bar

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM