Xamarin Forms Android 工具栏文本颜色

5

工具栏默认的颜色是白色,我想把它改成蓝色。几乎所有的东西我都能改变,但就是改不了这个。

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

3个回答

8

我找到了一种方法。它与我在其他地方读到的所有答案混合在一起。 我使用了@Guillermo Daniel Arias在styles.XML中提供的回答。

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

在App.xml文件中 (在Xamarin Forms共享项目中)
 <Style TargetType="NavigationPage">
        <Setter Property="BarBackgroundColor" Value="White"/>
        <Setter Property="BarTextColor" Value="#004895"/>
        </Style>

enter image description here


2

有两种可能的方法:

  • 您可以更改NavigationPageBarBackgroundColorBarTextColor。 在您的情况下,应该是这样的:

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:可能是问题所在,因为我按照我说的方式做,它可以工作。


非常感谢!我会尝试第二个。保持联系。 - Pxaml

0
在 App.xml 中添加以下内容:
 <Application.Resources>
    <ResourceDictionary>
        <Color x:Key="mRed">#65508F</Color>
        <Color x:Key="mWhite">#FFFFFF</Color>

        <Style TargetType="NavigationPage">
            <Setter Property="BarBackgroundColor" Value="{StaticResource mRed}" />
            <Setter Property="BarTextColor" Value="{StaticResource mWhite}" />
        </Style>
    </ResourceDictionary>
</Application.Resources>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接