c# - 如何更改底部标签的背景颜色
问题描述
我正在努力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);
}
}
输出我得到截图:
解决方案
你可以试试这个。
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 上查看此示例。
推荐阅读
- c++ - 使用循环为不同的结构变量分配不同的值
- python - ValueError:负尺寸大小是由 1 减去 12 导致的,输入形状为“max_pooling2d_1/MaxPool”(操作:“MaxPool”):[?,1,1,64]
- amazon-dynamodb - dynamoDB 的写入一致性能否保证事务性写入?
- spring-boot - 通过PasswordEncoder编码并在spring boot security中使用jwt生成后获取密码
- node.js - 在本地连接 node.js PostgreSQL 数据库和 Vue 客户端
- javascript - React Native onPress 自动触发
- python - 如何从具有 True 值的列名称创建新列
- ios - 集合视图或 uitableview 内的 Stackview
- c - 如何为内核创建文本包装器?
- c - 文件处理中的字符串变量不起作用