How to dynamicaly change Android Toolbar icons color
With the new Palette library and Material design, we’re able to create more color-aware applications, implementing color adaptable user interfaces.
TL;DR There’s a link to the ColorizeToolbarHelper class at the end of the article. It works out of the box.
Instead of using the same colors across the app, we’re can easily colorize the views, using leading colors of on screen visible pictures.
Here are examples of few views already colorized according to the leading image palette.
Todays article is focused on dynamic colorizing of Toolbar views (icons and textviews), so they fit the color scheme choosen by palette algorithms (Please follow this link to find out how to use Palette library).
As achieving this with use of Themes may turn impossible, we took different approach, where each toolbars child-view is colorized with ColorFilter. It’s achieved in 4 steps:
- Changing the color of back button (or open drawer button).
- Changing the color of any ActionMenuViews – icons that are not back button, nor text, nor overflow menu icon.
- Changing the color of title and subtitle.
- Changing the color of the Overflow Menu icon.
The following code is based on Compatibility libraries (Appcompat, and Palette) so it will work not only on Lollipop, but on all Android devices (as regular Appcompat based apps).
Let’s color it up!
To get all Toolbar views, we iterate through all it’s child views and colorize them separately. The loop code for it looks like this:
Источник
question
Xamarin Forms change ToolbarItem icon color on Android
I’ve icons which created in black colour. When I add them to toolbar in iOS they are automatically showing in white colour:
On Android icons are shown in black colour:
Question: how can I change toolbar item icon colour in Android? is there some setting in Android styles that I can apply so all images has white tint/colour?
Is this even possible on Android, or do I need to have 2 sets of images, e.g. black and white?
Another approach would be to use my own NavigationBar in every page, but would rather avoid doing this if possible.
1 Answer
Welcome to our Microsoft Q&A platform!
I’ve icons which created in black colour. When I add them to toolbar in iOS they are automatically showing in white colour
This is because the icon will be turned to the default theme color in iOS, and not shrunk.
how can I change toolbar item icon colour in Android?
For this function, try creating a custom page renderer to obtain the toolbarItem from the page. Then re-set the color for the toolbar items. Here is the sample code, you could refer to it.
If the response is helpful, please click «Accept Answer» and upvote it.
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.
Источник