Xamarin构成Android工具栏文本颜色

问题描述 投票:2回答:2

工具栏颜色默认为白色,我想将其更改为蓝色。我几乎可以改变一切,但不是。

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" /> 

styles.xml

<style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
       <item name="android:textColorPrimary">#1b2b32</item>
      <item name="android:textColorSecondary">#1c4d9e</item>

logout text is always in white

xamarin.forms xamarin.android
2个回答
2
投票

有两种可能的方法:

  • 你改变你的BarBackgroundColorBarTextColorNavigationPage。在你的情况下,它会是这样的:

MainPage = new NavigationPage(new YourPage())
{
      BarBackgroundColor = Color.White,
      BarTextColor = Color.Blue
};
  • 另一种方法是设置您的Android样式。你已经这样做了,但我认为那是错的。而不是android:textColorPrimaryandroid:textColorSecondary`,尝试类似的东西:

<style name="MyTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">#FFFFFF</item>
    <item name="colorSecondary">#0000FF</item>
    <item name="colorAccent">#0000FF</item>
</style>

我认为android:可能是问题,因为我的行为与我说的完全一样,并且它正在发挥作用。


1
投票

我找到了一种方法。它与我在那里读到的所有答案混合在一起。我使用了Change color of ToolBarItem in XAML @Guillermo Daniel Arias的回答。在styles.XML上

<item name="android:actionMenuTextColor">#1c4d9e</item>

在App.xaml上(在xamarin表单共享项目中)

 <Style TargetType="NavigationPage">
        <Setter Property="BarBackgroundColor" Value="White"/>
        <Setter Property="BarTextColor" Value="#004895"/>
        </Style>

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.