首页 > 解决方案 > 如何更改底部标签的背景颜色

问题描述

我正在努力Xamarin.Forms。我的 android 项目中有底部标签。选项卡显示默认背景颜色为浅灰色。我需要将标签背景颜色更改为我喜欢的颜色。但我不能这样做。我正在使用下面的代码

MainPage.xaml 文件

<?xml version="1.0" encoding="utf-8"?>
<MyTabbedPage 
 xmlns="http://xamarin.com/schemas/2014/forms" 
 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
 xmlns:local="clr-namespace:edTheSIS"    
 x:Class="edTheSIS.ParentDashboard">
<local:DairyTabPage  Icon="icon1"></local:DairyTabPage>
<local:MykidTabPage  Icon="icon2" ></local:MykidTab>
<local:EventsPage   Icon="icon3"></local:Events>
<local:AboutPage    Icon="icon4"></local:About>
</MyTabbedPage>

MyTabbedPage.cs 文件

public class MyTabbedPage : Xamarin.Forms.TabbedPage
{
    public MyTabbedPage()
    {
        On<Xamarin.Forms.PlatformConfiguration.Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);
    }
} 

输出我得到截图:

在此处输入图像描述

标签: c#xamarinxamarin.formstabs

解决方案


你可以试试这个。

On<Xamarin.Forms.PlatformConfiguration.Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);

On<Xamarin.Forms.PlatformConfiguration.Android>().SetBarSelectedItemColor(Color.White); --> to change the selected color tabitem

On<Xamarin.Forms.PlatformConfiguration.Android>().SetBarItemColor(Color.Gray); --> Gray is the default color but you can also change this to any color.

例子 :

On<Xamarin.Forms.PlatformConfiguration.Android>().SetBarItemColor(Color.Green);

如果您使用的是 FormsAppCompatActivity,则可以使用

app:tabIndicatorColor="#FF3300" <!-- Set indicator color here, sets it to red-->

编辑

您需要创建一个自定义渲染器。

在 github 上查看此示例。


推荐阅读