Changing color of 3 dots in Toolbar .net Maui

Dustin 41 Reputation points
2022-09-23T10:16:49.05+00:00

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.
2,147 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 58,011 Reputation points Microsoft Vendor
    2022-09-26T05:50:01.263+00:00

    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.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Gnana 5 Reputation points
    2023-09-25T15:06:52.7+00:00

    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