我正在编写一个具有 TabBar 的应用程序。在 iOS 上,我想将所选项目的突出显示更改为绿色而不是默认的蓝色。
我可以在创建 TabbedPage 时使用这行代码: BarTextColor = Color.FromHex("#27b286");
这会按照我的意愿更改图标颜色,但它也会更改所有选项卡上的文本颜色,而不仅仅是选定的选项卡(我希望选定的选项卡文本为绿色)。
TabPage 代码为:
NavigationPage.SetHasNavigationBar(this, false);
if(Device.RuntimePlatform == "iOS")
{
BarBackgroundColor = Color.White;
//BarTextColor = Color.FromHex("#27b286");
Children.Add(new CoinsPage() { Title = "Coins", Icon = "coins.png" });
Children.Add(new PortfolioPage() { Title = "Portfolio", Icon = "portfolio.png" });
Children.Add(new TrendingPage() { Title = "Trending", Icon = "trending.png" });
Children.Add(new SettingsPage() { Title = "Settings", Icon = "settings.png" });
}
如何让选中的选项卡文本颜色仅为绿色?
请您参考如下方法:
不确定这是否旨在像那样工作。我认为这是有道理的,因为我们设置的是 text 颜色,而不是所选颜色或类似颜色。
所以,现在似乎没有办法从纯 Forms 中做到这一点。
要为 iOS 设置它,请进入 AppDelegate.cs 文件并在您的 FinishedLaunching 方法中添加以下行:
UITabBar.Appearance.TintColor = UIColor.Red;
当然,用你自己的颜色替换。它现在应该只是彩色的所选项目。
