Sign in
Log inSign up
Julian Ewers-Peters

6 likes

·

47.6K reads

15 comments

steven
steven
May 18, 2023

How do I globally set the colour of the title bar?

1
·
·1 reply
Julian Ewers-Peters
Julian Ewers-Peters
Author
·May 18, 2023

If you're using Shell, you can navigate to the Styles.xaml file and then find the style setter for the Shell.BackgroundColor property:

<Setter Property="Shell.BackgroundColor" Value="{AppThemeBinding Light=#123456, Dark=#654321" />

Or when you use a NavigationPage or TabbedPage, you can set the BarBackgroundColor:

    <Setter Property="BarBackgroundColor" Value="{AppThemeBinding Light={StaticResource Primary}, Dark={StaticResource Gray950}}" />

Of course, you don't need to use the AppThemeBinding, you can also set it to a single, static value.

1
·
Thomas Schreiner
Thomas Schreiner
Jun 7, 2023

Thank you for this. Exactly what I was looking for. Well written. You made it easy to understand.

1
·
·1 reply
Julian Ewers-Peters
Julian Ewers-Peters
Author
·Jun 7, 2023

Thank you, Thomas Schreiner! I'm happy that it helps you.

·
Julian Ewers-Peters
Julian Ewers-Peters
Author
·Apr 13, 2023

I've noticed a few issues on iOS and I didn't want to include workarounds in this blog post to keep it clean. The respective issues are filed in the MAUI GitHub repository: github.com/dotnet/maui/issues/14558, github.com/dotnet/maui/issues/14559

·
Sebastian Hoppe
Sebastian Hoppe
Aug 25, 2023

Hi,

how do I change the background (which is white on your screenshot) and text color of the secondary items?

Thanks in advance. Sebastian.

·
·1 reply
Julian Ewers-Peters
Julian Ewers-Peters
Author
·Aug 27, 2023

Hi Sebastian Hoppe,

which background do you mean?

On the top, you can see the status bar, which on Android can be set in the platform-specific code, e.g. MainActivity.cs via this method:

Window?.SetStatusBarColor(Colors.Orange.ToAndroid());

On iOS, this shouldn't be necessary, usually the page background color is used, which can be set in a platform-independent fashion like this:

<ContentPage
    BackgroundColor="Orange">

</ContentPage>

I hope this helps.

I'm thinking about writing a separate blog post about that.

Cheers Julian

·
Sebastian Hoppe
Sebastian Hoppe
Aug 25, 2023

P.S.: Actually, it regards to all popup views, such as alert views (DisplayAlert(...)), picker selection views and others. That's why - in my case - it would be sensible to add a theme for that. But how?

·
·2 replies
Julian Ewers-Peters
Julian Ewers-Peters
Author
·Aug 27, 2023

Hi Sebastian Hoppe,

popups such as alert dialogs and the picker use native platform views. In order to theme those, you need to use platform-specific code.

This can be achieved either by using custom renderers (the old-fashioned Xamarin.Forms way), control customization using handlers and mappers or by manually setting color values in the styles.xml of the Android platform, similar to how I have described it in my blog post about splash screens in MAUI.

I hope this helps.

Cheers Julian

·
Sebastian Hoppe
Sebastian Hoppe
Aug 29, 2023

Hi Julian Ewers-Peters,

actually I tried Handler (found one to change the color of the "3-point-item" but sadly not for the popup background color). In the colors.xml I could change the default purple color of the dialog buttons which is hard to see on dark grey background. If you are able to change the background color of the popup, that contains your secondary toolbar items, to green which would fit your color style nicely please let me know. :-)

Regards. Sebastian.

·
Sebastian Hoppe
Sebastian Hoppe
Aug 29, 2023

Hi Julian,

I have another question for you regarding the toolbar items. It's great to add icons to the toolbar and even in different colors. Is it also possible to change the color of them in runtime and if yes, how?

Thanks in advance! Sebastian.

·
·1 reply
Julian Ewers-Peters
Julian Ewers-Peters
Author
·Sep 8, 2023

Hi Sebastian.

Sorry, I didn't see your comment before.

Have you tried using data binding to change the color during runtime?

Another approach would be to build the toolbar in the code-behind using C# and then setting different colors based on some conditions.

As I am not near my computer at the moment, I won't be able to give a specific answer at the moment.

If you can't figure it out, let me know and I might write up another blog post about configuring/updating the toolbar from the code-behind during runtime.

Cheers Julian

·
Sayyad Hasan
Sayyad Hasan
Nov 14, 2023

Awesome, I was looking something like this

·
Edison J. Romo R.
Edison J. Romo R.
Jun 28, 2024

Where I set ContentPage.ToolbarItems? in Shell.App or in a new ContentPage.xaml? This tutorial is incomplete!

·