Maui for android NavigationBar backgroundColor

Haviv Elbsz 2,071 Reputation points
2023-09-06T20:25:25.14+00:00

Hello all. Please how do I change NavigationBar backgroundColor to color "#ECE5DD" Thank you very much.

Developer technologies .NET .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2023-09-08T01:34:44.8533333+00:00

    Hello,

    After investigation, you could change the system navigation bar color by adding the following code to the Android MainActivity class in the MAUI program.

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        Window.SetNavigationBarColor(Android.Graphics.Color.ParseColor("#ECE5DD"));
    }
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    1 deleted comment

    Comments have been turned off. Learn more

  2. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2023-09-07T08:56:29.3666667+00:00

    Hello,

    I'm not sure if AppShell is the MainPage in App class.

    If so, you could change the Shell.BackgroundColor and modify the style for Shell in Resources/Styles/Styles.xaml.

    Detail Steps:

    Define color in Resources/Styles/Colors.xaml

    <Color x:Key="NavigationBarColor">#ECE5DD</Color>
    

    Modify Shell.BackgroundColor

    <Style TargetType="Shell" ApplyToDerivedTypes="True">
            <Setter Property="Shell.BackgroundColor" Value="{AppThemeBinding Light={StaticResource NavigationBarColor}, Dark={StaticResource NavigationBarColor}}" />
           ...
        </Style>
    

    Or you could set the color in a ContentPage

    <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
               Shell.BackgroundColor="XXX">
    

    If the MainPage is NavigationPage like the following code:

    public App()
        {
            InitializeComponent();
    
       //    MainPage = new AppShell();
        MainPage = new NavigationPage(new NewPage1());
        }
    

    You could modify the BarBackgroundColor of NavigationPage

    <Style TargetType="NavigationPage">
            <Setter Property="BarBackgroundColor" Value="{AppThemeBinding Light={StaticResource NavigationBarColor}, Dark={StaticResource NavigationBarColor}}" />
        </Style>
    

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.