Share via

Changing color of 3 dots in Toolbar .net Maui

Dustin 41 Reputation points
Sep 23, 2022, 10:16 AM

In my project I have secondary toolbar items. For every other item in the toolbar I have a white design. How can I change the color if the 3 dots in my toolbar.

244235-screenshot.png

I specified the Toolbaritems in .xaml file.

<ContentPage.ToolbarItems>
<ToolbarItem IconImageSource="notification_icon.png" Order="Primary" Clicked="OnNotificationButtonClicked"/>
<ToolbarItem Text="Test1" Order="Secondary"/>
<ToolbarItem Text="Test2" Order="Secondary"/>
<ToolbarItem Text="Test3" Order="Secondary"/>
<ToolbarItem Text="Test4" Order="Secondary"/>
</ContentPage.ToolbarItems>

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,072 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 81,191 Reputation points Microsoft External Staff
    Sep 26, 2022, 5:50 AM

    Hello,

    In the android, you can following code to set the three icon to white. but you need to get the toolbar.

       toolbar.OverflowIcon.SetTint(ContextCompat.GetColor(Microsoft.Maui.ApplicationModel.Platform.CurrentActivity,Resource.Color.m3_ref_palette_white));  
    

    If you use Shell, You can use custom renderer to get toolbar and set color of three dots.

    Firstly, you need to create a shell renderer class in Android folder and set the color of three dots like following code.

       public class MyShellRenderer:ShellRenderer  
           {  
               public MyShellRenderer(Context context) : base(context)  
               {  
         
              }  
              protected override IShellToolbarAppearanceTracker CreateToolbarAppearanceTracker()  
               {  
                   return new MyToolbarAppearanceTracker();  
               }  
           }  
          internal class MyToolbarAppearanceTracker : IShellToolbarAppearanceTracker  
           {  
               public void Dispose()  
               {  
                   
               }  
         
              public void ResetAppearance(AndroidX.AppCompat.Widget.Toolbar toolbar, IShellToolbarTracker toolbarTracker)  
               {  
                  
               }  
              public void SetAppearance(AndroidX.AppCompat.Widget.Toolbar toolbar, IShellToolbarTracker toolbarTracker, ShellAppearance appearance)  
               {              
                   toolbar.OverflowIcon.SetTint(ContextCompat.GetColor(Microsoft.Maui.ApplicationModel.Platform.CurrentActivity,Resource.Color.m3_ref_palette_white));  
               }  
           }  
    

    Then you need to register this custom renderer for shell in MauiProgram.cs.

       builder  
                   .UseMauiApp<App>()  
                   .ConfigureFonts(fonts =>  
                   {  
                       fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");  
                       fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");  
                   }).ConfigureMauiHandlers((handlers) =>  
                   {  
       #if ANDROID  
                       handlers.AddHandler(typeof(Microsoft.Maui.Controls.Shell),typeof(YourProject.Platforms.Android.MyShellRenderer));  
       #endif  
                   }  
    

    Best Regards,

    Leon Lu


    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.

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Gnana 5 Reputation points
    Sep 25, 2023, 3:06 PM

    Thanks for the detailed info.

    Just curious. By default, iOS gets a white colored icon.

    or rendered required for iOS too?

    0 comments No comments

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.