I can't change navbar color!

phknupphknup ✭✭BRMember ✭✭

Hi guys.

I'm handling a problem that should not be so hard to get out.

I can't change the navbar/toolbar colors. No matter what I do, it dont change!

It is always this white:

Things I've already done:

Reinstalled the xamarin forms, v7 appcompat library, custom styles, clean and rebuild project...

I can change text color but not the BarBackgroundColor. Not even accent color, apparently.

My styles.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="Theme.Splash" parent ="Theme.AppCompat.Light.NoActionBar">
   <item name="android:windowBackground">@drawable/splash</item>
   <item name="android:windowNoTitle">true</item>
   <item name="android:windowFullscreen">true</item>
 </style>


  <style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:colorPrimary">#25aaed</item>
    <item name="android:colorPrimaryDark">#25aaed</item>
    <item name="android:colorAccent">#25aaed</item>
  </style>

</resources>

A piece of MainActivity:

[Activity(Label = "caronapp", Icon = "@drawable/icon", Theme = "@style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : FormsAppCompatActivity
{
    public static ICallbackManager CallbackManager = CallbackManagerFactory.Create();
    public static readonly string[] PERMISSIONS = new[] { "publish_actions" };

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        FacebookSdk.SdkInitialize(this.ApplicationContext);
        global::Xamarin.Forms.Forms.Init(this, bundle);
        LoadApplication(new App());
    }

Toolbar.axml:

<?xml version="1.0" encoding="utf-8"?>
<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:minHeight="?android:attr/actionBarSize"
   android:background="?android:attr/colorPrimary" />'

Where mainpage is created and called:

MainPage = new NavigationPage(new MainPage(token)) { BarBackgroundColor=Color.Lime, Tint=Color.Lime};

As you can see, I'm trying hard to change the color. Setting everything to #25aaaed or even Lime. I just want to change this boring white.

Am I missing something?

Thanks!

Posts

  • NashZhouNashZhou ✭✭✭ USMember ✭✭✭

    BarBackgroundColor should work if you're starting with a blank application though it looks like you changed some things.

    One main difference I see on a new Xamarin Forms application and your code is your MainActivity in your Android specific project

    protected override void OnCreate(Bundle bundle)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;
    
        base.OnCreate(bundle);
        global::Xamarin.Forms.Forms.Init(this, bundle);
        LoadApplication(new App());
    }
    

    Now I tried removing TabLayoutResource = Resource.Layout.Tabbar and ToolbarResource = Resource.Layout.Toolbar and lost the ability to change the bar background color, but not the bar text color.

    Try adding those 2 things back into you MainActivity and if that doesn't work, it would be helpful to see the Android manifest.

  • phknupphknup ✭✭ BRMember ✭✭
    edited August 2017

    @NashZhou said:
    BarBackgroundColor should work if you're starting with a blank application though it looks like you changed some things.

    One main difference I see on a new Xamarin Forms application and your code is your MainActivity in your Android specific project

    protected override void OnCreate(Bundle bundle)
    {
      TabLayoutResource = Resource.Layout.Tabbar;
      ToolbarResource = Resource.Layout.Toolbar;
      
      base.OnCreate(bundle);
      global::Xamarin.Forms.Forms.Init(this, bundle);
      LoadApplication(new App());
    }
    

    Now I tried removing TabLayoutResource = Resource.Layout.Tabbar and ToolbarResource = Resource.Layout.Toolbar and lost the ability to change the bar background color, but not the bar text color.

    Try adding those 2 things back into you MainActivity and if that doesn't work, it would be helpful to see the Android manifest.

    It works!!!

    Thank you Nash Zhou. I was comparing with a working solution and I can't figure out how I didn't notice this
    mismatch.

  • RasmusChristensenRasmusChristensen ✭✭ DKUniversity ✭✭

    Had exactly the same issue. For some reason I was not running AppCompat to start with. Then the Toolbar files was missing in Layout. Adding them from another working project and the adding the 2 lines fixed everything.

Sign In or Register to comment.