Xamarin将图像添加到导航栏
我有个问题。我用Shell创建了一个母版详细信息页面。但是现在我想在导航栏中添加一个图像,所以我想说清楚:一个图像。。。不是一个图标 这是我现在的代码:Xamarin将图像添加到导航栏,xamarin,xamarin.forms,xamarin.android,xamarin.ios,Xamarin,Xamarin.forms,Xamarin.android,Xamarin.ios,我有个问题。我用Shell创建了一个母版详细信息页面。但是现在我想在导航栏中添加一个图像,所以我想说清楚:一个图像。。。不是一个图标 这是我现在的代码: <?xml version="1.0" encoding="utf-8" ?> <Shell xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xm
<?xml version="1.0" encoding="utf-8" ?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MyApp"
x:Class="MyApp.SideMenuItems" BackgroundColor="#212121"
FlyoutBackgroundColor="#212121">
<Shell.FlyoutHeader>
<local:SideMenuHeader />
</Shell.FlyoutHeader>
<Shell.ItemTemplate>
<DataTemplate>
<StackLayout HorizontalOptions="StartAndExpand" Orientation="Horizontal" Padding="30, 15, 0, 15">
<Image Source="{Binding Icon}" HeightRequest="35" />
<Label Text="{Binding Title}" TextColor="White" FontSize="Large" VerticalOptions="Center" HorizontalOptions="Start" />
</StackLayout>
</DataTemplate>
</Shell.ItemTemplate>
<FlyoutItem Title="SideNav"
Shell.TabBarIsVisible="False"
FlyoutDisplayOptions="AsMultipleItems">
<ShellContent Title="Home" Icon="Home_Dark.png" IsTabStop="true" ContentTemplate="{DataTemplate local:HomePage}"/>
<ShellContent Title="Search" Icon="Search_Dark.png" IsTabStop="true" ContentTemplate="{DataTemplate local:HomePage}" />
<ShellContent Title="Messages" Icon="Chats_Dark.png" IsTabStop="true" ContentTemplate="{DataTemplate local:HomePage}" />
<ShellContent Title="Favorites" Icon="Favorites_Dark.png" IsTabStop="true" ContentTemplate="{DataTemplate local:HomePage}" />
<ShellContent Title="Settings" Icon="Settings_Dark.png" IsTabStop="true" ContentTemplate="{DataTemplate local:HomePage}" />
</FlyoutItem>
</Shell>
如何将图像添加到中心的顶部导航栏
我试过这个:
<Shell.TitleView>
<Image Source="Title_Dark.png" HeightRequest="30" VerticalOptions="CenterAndExpand" />
</Shell.TitleView>
但是屏幕上没有图像吗?我还没有测试过,但是您应该能够在带有Shell的XAML中使用
TitleView
,所以将它添加到那里
如果您在shell的导航栏中显示视图,则将以下代码添加到主页Comtent页面
<ContentPage ...>
<Shell.TitleView>
<Image Source="xamarin_logo.png"
HorizontalOptions="Center"
VerticalOptions="Center" />
</Shell.TitleView>
...
...
Shell类定义了类型为View的TitleView attached属性,该属性允许在导航栏中显示任何Xamarin.Forms视图
虽然此属性可以在子类Shell对象上设置,但也可以在希望在导航栏中显示视图的任何页面上设置
有关更多详细信息,您可以查看:
更新:
如果要更改导航栏的高度大小,可以在android项目的style.xml文件中调用android:actionBarSize
<style name="MainTheme" parent="MainTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<!-- Set theme colors from https://aka.ms/material-colors -->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#2196F3</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#1976D2</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#FF4081</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
<item name="windowActionModeOverlay">true</item>
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
<item name="android:actionBarSize">250dp</item>
</style>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#FF4081</item>
</style>
真的
假的
#2196F3
#1976D2
#FF4081
真的
@样式/应用程序对话框样式
250dp
#FF4081
如果我的回复对您有帮助,请记住将我的回复标记为回答,谢谢。通常,我会将导航栏显示设置为false,并将自己的导航栏视图创建为contentview。因此,您可以根据自己的需要对其进行自定义@A.Vreeswijk我建议您在ContentPage上尝试一下。但它不是导航页面,而是Shell(母版详细信息页面)。ContentPage中没有标题视图,只有NavigationPage中,如何设置高度。。。HeightRequest没有work@A.Vreeswijk,请查看我的更新,请记住将我的回复标记为答案,如果我的回复对您有帮助,谢谢。