白色 ToolbarItem 图标显示黑色

时间:2021-03-21 17:41:34

标签: xamarin.forms xamarin.android

我有一个包含 TabbedPage 的 Xamarin Forms NavigationPage,我正在设置一个带有两个白色图标的 ToolbarItem。出于某种原因,当我的图标为白色时,它们显示为黑色:

enter image description here

这是我的 Xaml 代码:

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:views="clr-namespace:Pick.Views"
            x:Class="Pick.Views.MainView"
            xmlns:utility="clr-namespace:Pick.Utility"
            utility:ViewModelLocator.AutoWireViewModel="False">
       
        <NavigationPage Title="{Binding Strings[Menu_MyPools]}">
            <x:Arguments>
                <views:PoolsView BindingContext="{Binding PoolsViewModel}"/>
            </x:Arguments>
            <NavigationPage.ToolbarItems>
            <ToolbarItem Command="{Binding CreatePoolCommand}" Order="Primary" IconImageSource="ic_add_white_36dp.png">
            </ToolbarItem>
            <ToolbarItem Command="{Binding JoinPoolCommand}" Order="Primary" IconImageSource="ic_login_white_36dp.png">
            </ToolbarItem>                
            </NavigationPage.ToolbarItems>
        </NavigationPage>

我尝试设置 AppThemeBinding 并更改 Styles.xml 但似乎没有任何效果:

    <ToolbarItem Command="{Binding CreatePoolCommand}" Order="Primary">
        <ToolbarItem.IconImageSource>
            <OnPlatform x:TypeArguments="ImageSource">
                <On Platform="Android" Value="{AppThemeBinding Light=ic_add_white_36dp,Dark=ic_add_white_36dp}"/>
                <On Platform="iOS" Value="{AppThemeBinding Light=ic_add_white_36pt,Dark=ic_add_white_36dp}"/>
            </OnPlatform>
        </ToolbarItem.IconImageSource>
    </ToolbarItem>

有什么想法吗?

这里是我的styles.xml:

<resources>

  <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 http://www.google.com/design/spec/style/color.html#color-color-palette -->
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">#188223</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>
  </style>

  <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">#FF4081</item>
  </style>
</resources>

Tabbar.axml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:tabIndicatorColor="@android:color/white"
    app:tabGravity="fill"
    app:tabMode="fixed" />

Toolbar.axml:

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

1 个答案:

答案 0 :(得分:0)

我刚刚发现了我的问题。原来我有与我的图像相对应的 XML 文件,里面有一个矢量定义。不确定这些是否是由我的材料设计图标 VS 扩展程序之一自动创建的。删除后,我会看到我的图标颜色正确。

enter image description here