我有一个.Net Maui应用程序,它使用Shell TabBar:
<TabBar>
<Tab Title="Home" Icon="{StaticResource IconHome}">
<ShellContent ContentTemplate="{DataTemplate local:MainPage}" />
</Tab>
<Tab Title="Coverage Calculator" Icon="{StaticResource IconCalculator}" >
<ShellContent ContentTemplate="{DataTemplate calculator:CoverageCalculatorPage}" />
</Tab>
<Tab Title="Distributor Locator" Icon="{StaticResource IconLocator}">
<ShellContent ContentTemplate="{DataTemplate locator:DistributorsLocatorPage}" />
</Tab>
<Tab Title="Scan QR Code" Icon="{StaticResource IconQrScanner}">
<ShellContent ContentTemplate="{DataTemplate qrScanner:QrScannerPage}" />
</Tab>
<Tab Title="More" Icon="{StaticResource IconMore}">
<ShellContent ContentTemplate="{DataTemplate more:MoreFeaturesPage}" />
</Tab>
</TabBar>
图标 colored颜色 在Styles.xaml中设置如下:
<Setter Property="Shell.TabBarUnselectedColor" Value="{AppThemeBinding Light={StaticResource LaticreteColor}, Dark={StaticResource LaticreteColor}}" />
下面是选项卡栏的外观:
因为我的标签需要多行文本,所以我为Android应用了一个定制的呈现器:
internal class LaticreteShellRenderer : ShellRenderer
{
public LaticreteShellRenderer(Context context) : base(context) { }
protected override IShellBottomNavViewAppearanceTracker CreateBottomNavViewAppearanceTracker(ShellItem shellItem)
{
return new LaticreteTabLayout();
}
public class LaticreteTabLayout : Java.Lang.Object, IShellBottomNavViewAppearanceTracker
{
public void ResetAppearance(BottomNavigationView bottomView)
{
throw new NotImplementedException();
}
public override void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
{
bottomView.SetMinimumHeight(180);
var bottomNavView = bottomView.GetChildAt(0) as BottomNavigationMenuView;
for (int i = 0; i < bottomNavView.ChildCount; i++)
{
var item = bottomNavView.GetChildAt(i) as BottomNavigationItemView;
var itemTitle = item.GetChildAt(1);
TextView smallTextView = (TextView)((BaselineLayout)itemTitle).GetChildAt(0);
TextView largeTextView = (TextView)((BaselineLayout)itemTitle).GetChildAt(1);
smallTextView.SetLines(2);
largeTextView.SetLines(2);
}
}
这将重置选项卡的 colored颜色 :
我发现我可以这样更改自定义渲染器中的文本 colored颜色 :
smallTextView.SetTextColor(global::Android.Graphics.Color.Brown);
largeTextView.SetTextColor(global::Android.Graphics.Color.Brown);
但我仍然不知道如何设置图标 colored颜色 ,以及如何在App.xaml或Colors.xaml中引用我的自定义 colored颜色 集.
请告知为什么重置选项卡栏未 Select 的 colored颜色 ,以及如何修复此问题.