如何更改底部标签的背景色 [英] How do I change bottom tabs background color
本文介绍了如何更改底部标签的背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究Xamarin.Forms
.我的Android项目中有底部标签.选项卡显示的默认背景色为浅灰色.我需要将标签的背景色更改为我的首选颜色.但是我不能这样做.
我正在使用的以下代码
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文件
<?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);
}
}
输出我正在获取屏幕截图:
Output I am getting screenshot:
推荐答案
您可以尝试一下.
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,则可以使用
If you are using FormsAppCompatActivity, you can use
app:tabIndicatorColor="#FF3300" <!-- Set indicator color here, sets it to red-->
修改
您需要创建一个自定义渲染器.
You'll need to create a custom renderer.
在github上检查此示例.
Check this sample on github.
这篇关于如何更改底部标签的背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文