【问题标题】:Changing ToolbarItem text color via xaml to all platform(Android,iOS,UWP)通过 xaml 将 ToolbarItem 文本颜色更改为所有平台(Android、iOS、UWP)
【发布时间】:2020-05-16 23:53:15
【问题描述】:

enter image description here这是我的 xaml 代码:

ContentPage.ToolbarItems ToolbarItem Text="+" Priority="0" Order="Primary" Command="{Binding PrikaziCommand}" 工具栏项 ContentPage.ToolbarItems

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

【问题讨论】:

  • 请发布您的代码库示例。
  • 我没有看到任何 XAML!!!!
  • 我看到链接 MShah,但不要帮助我,需要我在 xaml 中才能特定于所有平台,这仅适用于 android,但我的 android 工作正常....我放置 xam 代码但是看不到可能是因为标签,我现在编辑没有标签的代码....
  • @Srki92 为什么不使用 navigation.title 视图

标签: xaml xamarin.forms textcolor toolbaritems


【解决方案1】:

如果你想改变你的工具栏文本颜色,你可以使用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");

【讨论】:

  • NavigationPage.TitleView 和 ContentPage.ToolbarItems 是两个不同的东西。ContentPage.ToolbarItems 没有 TextColor....
  • 是的。您可以使用 NavigationPage.TitleView 代替 contentpage.Toolbar 项目
  • 当我尝试在 NavigationPage.TitleView 中放置 2 个标签标签时,C# 表示属性“TitleView”设置了多次。
  • @Srki92 你想在你的工具中加入什么?
  • @Srki92 我编辑了我的答案。您应该将控件放在堆栈布局或框架中
猜你喜欢
  • 2018-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-12
  • 1970-01-01
相关资源
最近更新 更多