【问题标题】:Set Notification Bar same color than Navigation Bar Xamarin设置通知栏与导航栏 Xamarin 相同的颜色
【发布时间】:2017-06-29 02:19:30
【问题描述】:

我正在使用 Xamarin Forms 开展一个项目。 我跟着 James Montemagno 的指南 https://blog.xamarin.com/material-design-for-your-xamarin-forms-android-apps/ 但我无法在通知栏和导航栏中获得相同的颜色

我正在像这样在 App XAML 中设置导航栏颜色

     <ResourceDictionary>
        <Style TargetType="NavigationPage">
            <Setter Property="BarBackgroundColor" Value="#3b5998"/>
            <Setter Property="BarTextColor" Value="White"/>
        </Style>
    </ResourceDictionary>

style.xmlvalues-v21/style.xml 与指南中的相同

 <resources>
  <style name="MyTheme" parent="MyTheme.Base">
  </style>
  <style name="MyTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primaryDark</item>
    <item name="colorAccent">@color/accent</item>
    <item name="android:windowBackground">@color/window_background</item>
    <item name="windowActionModeOverlay">true</item>
  </style>
</resources>

<resources>
  <style name="MyTheme" parent="MyTheme.Base">
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">#3b5998</item>
  </style>
</resources>

我在 values-v21/style.xml 中设置了statusBarColor,一个罕见的情况是,当我开始调试应用程序时,通知栏会获得我设置的颜色,但是当应用程序完成启动时,它恢复原来的颜色。

这是截图

我想将通知栏的颜色设置为与导航栏相同。

感谢你们的帮助!

【问题讨论】:

    标签: xamarin xamarin.android xamarin.forms


    【解决方案1】:

    我必须重写 colorPrimaryDark 样式才能实现我想要的。

    <style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">#3b5998</item>
        <item name="colorPrimaryDark">#3b5998</item>
    </style>
    

    谢谢!

    【讨论】:

      【解决方案2】:

      状态栏和操作栏可以使用values/Styles.xml文件中的如下xml设置为相同颜色。

      <?xml version="1.0" encoding="utf-8" ?>
      <resources>
          <style name="myTheme" parent="android:Theme.Material.Light.DarkActionBar">
             <!-- Override the android colour scheme -->
             <item name="android:colorPrimary">@color/my_primary</item>
             <item name="android:statusBarColor">@color/my_primary</item>        
          </style>
      </resources>
      

      还要确保您的样式包含在 androidManifest.xml 中,并且您在 values/Colours.xml 文件中设置了自定义颜色。

      <application android:label="Settings" android:icon="@drawable/Icon" android:theme="@style/myTheme"></application>
      

      【讨论】:

      • 嗨 Aaron,我尝试了你的建议,但它不起作用,通知栏的颜色与导航栏的颜色不同
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-26
      相关资源
      最近更新 更多