问题
I am working on Xamarin.Forms. I have bottom tabs in my android project. Tabs are showing default background color something light gray. I need to change tabs background color to my preferred color. But I am not able to do so.
The code below I am using
MainPage.xaml file
<?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 file
public class MyTabbedPage : Xamarin.Forms.TabbedPage
{
public MyTabbedPage()
{
On<Xamarin.Forms.PlatformConfiguration.Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);
}
}
Output I am getting screenshot:
回答1:
You can try this out.
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.
Example :
On<Xamarin.Forms.PlatformConfiguration.Android>().SetBarItemColor(Color.Green);
If you are using FormsAppCompatActivity, you can use
app:tabIndicatorColor="#FF3300" <!-- Set indicator color here, sets it to red-->
Edit
You'll need to create a custom renderer.
Check this sample on github.
来源:https://stackoverflow.com/questions/51606756/how-do-i-change-bottom-tabs-background-color