Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何更改底部选项卡的背景色_C#_Xamarin_Xamarin.forms_Tabs - Fatal编程技术网

C# 如何更改底部选项卡的背景色

C# 如何更改底部选项卡的背景色,c#,xamarin,xamarin.forms,tabs,C#,Xamarin,Xamarin.forms,Tabs,我正在制作Xamarin.Forms。我的android项目中有底部选项卡。选项卡显示的是默认背景色,即浅灰色。我需要将标签的背景颜色更改为我喜欢的颜色。但我不能这样做。 下面的代码我正在使用 MainPage.xaml文件 <?xml version="1.0" encoding="utf-8"?> <MyTabbedPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.m

我正在制作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>
public class MyTabbedPage : Xamarin.Forms.TabbedPage
{
    public MyTabbedPage()
    {
        On<Xamarin.Forms.PlatformConfiguration.Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);
    }
} 

MyTabbedPage.cs文件

<?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>
public class MyTabbedPage : Xamarin.Forms.TabbedPage
{
    public MyTabbedPage()
    {
        On<Xamarin.Forms.PlatformConfiguration.Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);
    }
} 
公共类MyTabbedPage:Xamarin.Forms.TabbedPage
{
公共MyTabbedPage()
{
On().SetToolbarPlacement(ToolbarPlacement.Bottom);
}
} 
输出我得到的屏幕截图:

你可以试试这个

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().SetToolbarPlacement(ToolbarPlacement.Bottom);
On().SetBarSelectedItemColor(Color.White);-->更改选定颜色选项卡项的步骤
On().SetBarItemColor(Color.Gray);-->灰色是默认颜色,但也可以将其更改为任何颜色。
例如:

On<Xamarin.Forms.PlatformConfiguration.Android>().SetBarItemColor(Color.Green);
On().SetBarItemColor(Color.Green);
如果您正在使用FormsAppCompatActivity,则可以使用

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

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


查看github上的示例。

谢谢您的回答。它根本不改变背景色。其图标颜色和所选项目颜色不断变化。这是选项卡指示器颜色而不是背景颜色
app:tabIndicatorColor
。此外,底部的标签并没有使用原生android项目的布局。是的,我现在明白了。您将需要创建自定义渲染器。