I want to change the color of the active tab indictor dynamically. Multiple sources (Xamarin support, Xamarin docs) suggest there is a method that does just this, but it has to be done as a platform-specific for android
On<Android>().SetBarSelectedItemColor(color)
However, I'm testing this from the stock android template in Visual studio and it has no effect. It doesn't matter if I run it in the TabbedPage constructor, or as an event later.
Version info:
Xamarin Forms: 3.5.0.129452
Visual Studio: 15.9.7
Xamarin.Android SDK: 9.1.7.0
Do platform-specifics only work under certain conditions?
Code:
Other than a few color binding experiments, it is stock code.
MainPage.xaml.cs (Note: App.OnChange does get triggered and the code is executed as expected)
using System;
using Xamarin.Forms;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
using Xamarin.Forms.Xaml;
namespace App1.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MainPage : Xamarin.Forms.TabbedPage
{
public MainPage()
{
InitializeComponent();
App.OnChange((prop, value) =>
{
if (prop == App.ActiveColorKey)
{
On<Xamarin.Forms.PlatformConfiguration.Android>().SetBarSelectedItemColor(Color.FromHex(value));
On<Xamarin.Forms.PlatformConfiguration.Android>().SetBarItemColor(Color.FromHex(value));
}
});
}
}
}
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:App1.Views"
x:Class="App1.Views.MainPage" BarBackgroundColor="{DynamicResource TabColor}">
<TabbedPage.BarTextColor>
<OnPlatform x:TypeArguments="Color">
<On Platform="Android" Value="Green" />
</OnPlatform>
</TabbedPage.BarTextColor>
<TabbedPage.Children>
<NavigationPage Title="Browse">
<NavigationPage.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<On Platform="iOS" Value="tab_feed.png"/>
</OnPlatform>
</NavigationPage.Icon>
<x:Arguments>
<views:ItemsPage />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="About dog" BarBackgroundColor="Red" BackgroundColor="Yellow">
<NavigationPage.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<On Platform="iOS" Value="tab_about.png"/>
</OnPlatform>
</NavigationPage.Icon>
<x:Arguments>
<views:AboutPage />
</x:Arguments>
</NavigationPage>
</TabbedPage.Children>
</TabbedPage>