温馨提示:本文翻译自stackoverflow.com,查看原文请点击:xamarin.forms - Changing ToolbarItem text color via xaml to all platform(Android,iOS,UWP)
xamarin.forms xaml textcolor toolbaritems

xamarin.forms - 通过xaml将ToolbarItem文本颜色更改为所有平台(Android,iOS,UWP)

发布于 2020-03-31 23:04:51

在这里输入图片描述,这是我的xaml代码:

ContentPage.ToolbarItems ToolbarItem Text =“ +” Priority =“ 0” Order =“ Primary” Command =“ {Binding PrikaziCommand}” ToolbarItem ContentPage.ToolbarItems

如何通过xaml代码更改所有平台的文本颜色?

查看更多

提问者
Srki92
被浏览
129
AndroDevil 2020-02-03 20:21

如果要更改工具栏的文本颜色,可以使用Navigation.Titleview

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:TitleViewSample"
             x:Class="TitleViewSample.MainPage">

      <NavigationPage.TitleView>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>

            <Label Text="Your Title" Grid.Column="0" TextColor="White" FontSize="Large" VerticalOptions="Center" HorizontalOptions="FillAndExpand"></Label>

            <StackLayout Grid.Column="1" HorizontalOptions="EndAndExpand" Orientation="Horizontal" Margin="0,5,5,5">
                <Label Text="?" FontSize="Large" TextColor="Red" Margin="10" ></Label>
                <Label Text="+" FontSize="Large" TextColor="Green" Margin="10" ></Label>
            </StackLayout>
        </Grid>
</NavigationPage.TitleView>


</ContentPage>

如果要更改工具栏颜色,请在导航到特定页面时添加此代码

 MainPage = new NavigationPage(new YourPage());
((NavigationPage)MainPage).BarBackgroundColor = Color.FromHex("#19110F");

结果