How do I change bottom tabs background color

走远了吗. 提交于 2019-12-11 11:34:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!