Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin forms Android toolbar text-color

The toolbar color is by default white and I would like to change it to blue. I was able to change almost everything but not that.

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

like image 460
Pxaml Avatar asked Aug 28 '18 17:08

Pxaml


2 Answers

I found an approach. it is mixed with all the answers I read out there. I used this answer from Change color of ToolBarItem in XAML @Guillermo Daniel Arias. on styles.XML

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

on App.xml (On xamarin forms share project)

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

enter image description here

like image 62
Pxaml Avatar answered Sep 16 '22 22:09

Pxaml


There are two possible approaches:

  • You change the BarBackgroundColor and BarTextColor of your NavigationPage. In your case, it would be something like that:

MainPage = new NavigationPage(new YourPage())
{
      BarBackgroundColor = Color.White,
      BarTextColor = Color.Blue
};
  • The other approach is to set your Android styles. You're already doing that, but I think that's wrong. Instead of android:textColorPrimaryandroid:textColorSecondary`, try something like that:

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

I think that android: may be the problem, because I'm doing exactly like I said and it's working.

like image 32
Daniel Cunha Avatar answered Sep 20 '22 22:09

Daniel Cunha