C# 仅更改选定项目的选项卡栏文本颜色(Xamarin.Forms)
我正在编写一个有TabBar的应用程序。在iOS上,我想将所选项目的突出显示改为绿色,而不是默认的蓝色 我可以在创建选项卡页面时使用这行代码:C# 仅更改选定项目的选项卡栏文本颜色(Xamarin.Forms),c#,ios,xaml,xamarin.forms,C#,Ios,Xaml,Xamarin.forms,我正在编写一个有TabBar的应用程序。在iOS上,我想将所选项目的突出显示改为绿色,而不是默认的蓝色 我可以在创建选项卡页面时使用这行代码: BarTextColor=Color.FromHex(“#27b286”) 这会按我的要求更改图标颜色,但也会更改所有选项卡上的文本颜色,而不仅仅是所选选项卡上的文本颜色(我希望所选选项卡文本为绿色) 选项卡页代码为: NavigationPage.SetHasNavigationBar(this, false); if(Devi
BarTextColor=Color.FromHex(“#27b286”)代码>
这会按我的要求更改图标颜色,但也会更改所有选项卡上的文本颜色,而不仅仅是所选选项卡上的文本颜色(我希望所选选项卡文本为绿色)
选项卡页代码为:
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" });
}
如何仅将所选选项卡文本设置为绿色?不确定是否要这样操作。我认为这是有意义的,因为我们设置的是文本颜色,而不是选定的颜色或类似的东西
所以,现在似乎没有办法从纯形式上做到这一点
要将其设置为iOS,请进入AppDelegate.cs
文件,并在FinishedLaunching
方法中添加以下行:
uitabar.Appearance.TintColor=UIColor.Red代码>
当然,用您自己的颜色替换颜色。它现在应该是已着色的选定项。uitabar.Appearance.SelectedImageTintColor=UIColor.FromRGB(0、122、255)
在方法FinishedLaunching之后在IOS文件AppDelegate中更新此代码
加载应用程序(新应用程序()) 你现在的代码是什么?编辑了文章,包括了所有生成我的标签的代码,还有安卓系统吗?
// Color of the tabbar background:
UITabBar.Appearance.BarTintColor = UIColor.FromRGB(247, 247, 247);
// Color of the selected tab text color:
UITabBarItem.Appearance.SetTitleTextAttributes(
new UITextAttributes()
{
TextColor = UIColor.FromRGB(0, 122, 255)
},
UIControlState.Selected);
// Color of the unselected tab icon & text:
UITabBarItem.Appearance.SetTitleTextAttributes(
new UITextAttributes()
{
TextColor = UIColor.FromRGB(146, 146, 146)
},
UIControlState.Normal);