【问题标题】:How to change status bar colour while using xamarin shell如何在使用 xamarin shell 时更改状态栏颜色
【发布时间】:2020-06-05 05:22:56
【问题描述】:

我正在使用 Xamarin Shell 来显示导航抽屉和一些选项卡。 我需要更改状态栏颜色。我搜索了许多解决方案,但当我们不使用基于 Xamarin shell 的导航抽屉时,一切正常。

【问题讨论】:

    标签: xaml xamarin xamarin.forms xamarin.shell


    【解决方案1】:

    您也可以在内容页面 XAML 中执行此操作。当每页的条形颜色需要更改时,我更喜欢这种方式,我经常这样做。

    <?xml version="1.0" encoding="utf-8"?>
    <ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="BaseApp.Pages.MainMenuPage"
    Shell.BackgroundColor="{DynamicResource GradiantRedToOrange_End}"
    Shell.ForegroundColor="White"
    Shell.PresentationMode="Animated">
    

    更改导航栏背景颜色

    Shell.BackgroundColor="{DynamicResource GradiantRedToOrange_End}"
    

    更改标题文本和导航按钮颜色

     Shell.ForegroundColor="White"
    

    【讨论】:

      【解决方案2】:

      我们可以在资源字典中设置Shell导航栏的样式

         <Shell.Resources>
              <ResourceDictionary>
                  <Color x:Key="NavigationPrimary">#2196F3</Color>
                  <Style x:Key="BaseStyle" TargetType="Element">
                      <Setter Property="Shell.BackgroundColor" Value="Red" />  // set navigation bar color here
                      <Setter Property="Shell.ForegroundColor" Value="Blue" />
                      <Setter Property="Shell.TitleColor" Value="Blue" />
                      <Setter Property="Shell.DisabledColor" Value="#B4FFFFFF" />
                      <Setter Property="Shell.UnselectedColor" Value="#95FFFFFF" />
                      <Setter Property="Shell.TabBarBackgroundColor" Value="{StaticResource NavigationPrimary}" />
                      <Setter Property="Shell.TabBarForegroundColor" Value="White"/>
                      <Setter Property="Shell.TabBarUnselectedColor" Value="#95FFFFFF"/>
                      <Setter Property="Shell.TabBarTitleColor" Value="White"/>
                  </Style>
                  <Style TargetType="TabBar" BasedOn="{StaticResource BaseStyle}" />
              </ResourceDictionary>
          </Shell.Resources>
      

      【讨论】:

        猜你喜欢
        • 2019-12-31
        • 2021-11-05
        • 1970-01-01
        • 2021-02-04
        • 2019-06-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多