Xamarin Forms TabbedPage Tab Unselected Color [英] Xamarin Forms TabbedPage Tab Unselected Color
本文介绍了Xamarin Forms TabbedPage Tab Unselected Color的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试更改 TabbedPage 中未选择图标的颜色.
I'm trying to change the colour of the unselected icons from the TabbedPage.
我有一个自定义的 TabbedRenderer :
I have a custom TabbedRenderer :
public class CustomTabbedPage : TabbedRenderer
{
public override void ViewWillAppear(bool animated)
{
if (TabBar == null) return;
if (TabBar.Items == null) return;
var tabs = Element as TabbedPage;
if (tabs != null)
{
for (int i = 0; i < TabBar.Items.Length; i++)
{
UpdateItem(TabBar.Items[i], tabs.Children[i].Icon);
}
}
base.ViewWillAppear(animated);
}
private void UpdateItem(UITabBarItem item, string icon)
{
if (item == null)
return;
try
{
icon = icon.Replace(".png", " Filled.png");
if (item == null) return;
if (item.SelectedImage == null) return;
if (item.SelectedImage.AccessibilityIdentifier == icon) return;
item.SelectedImage = UIImage.FromBundle(icon);
item.SelectedImage.AccessibilityIdentifier = icon;
}
catch (Exception ex)
{
Console.WriteLine("Unable to set selected icon: " + ex);
}
}
}
我已成功更改了选定项目的文本颜色和未选定项目的文本颜色,但未更改图标颜色.
I have managed to change the selected item text colour and the unselected items text colour, but not the icon colours.
谢谢!
推荐答案
private void UpdateItem(UITabBarItem item, string icon)
{
if (item == null)
return;
try
{
string newIcon = icon.Replace(".png", " Filled.png");
if (item == null) return;
if (item.SelectedImage == null) return;
if (item.SelectedImage.AccessibilityIdentifier == icon) return;
item.Image = UIImage.FromBundle(icon);
item.Image = item.Image.ImageWithRenderingMode(UIKit.UIImageRenderingMode.AlwaysOriginal);
item.SelectedImage = UIImage.FromBundle(newIcon);
item.SelectedImage = item.SelectedImage.ImageWithRenderingMode(UIKit.UIImageRenderingMode.AlwaysOriginal);
item.SelectedImage.AccessibilityIdentifier = icon;
}
catch (Exception ex)
{
Console.WriteLine("Unable to set selected icon: " + ex);
}
}
这篇关于Xamarin Forms TabbedPage Tab Unselected Color的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文