android - 如何在 xamarin.forms for android 中设置选定选项卡的背景颜色?
问题描述
我在 xamarin.forms 工作。我已经在 android 中实现了底部标签页,如下面的代码
<TabbedPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Inika.Views.BottomBar.BottomBarPages"
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
BarBackgroundColor="White"
android:TabbedPage.ToolbarPlacement="Bottom"
android:TabbedPage.BarItemColor="#A9A9A9"
android:TabbedPage.BarSelectedItemColor="Black">
</TabbedPage>
我正在使用 xamarin.form 3.1 的新功能,如下链接
https://blog.xamarin.com/xamarin-forms-3-1-improvments/
根据我当前的代码,我的输出如下图所示
但我想设置选定选项卡的背景颜色。“BarBackgroundColor”属性设置整个Bar的颜色。我没有找到任何仅在选定选项卡中设置颜色的属性。
我需要这样的输出
请建议通过自定义渲染或任何解决方法,但我不想使用任何自定义插件。
解决方案
这个问题已经在 SO 上得到了回答。尽管如此,请尝试以下操作。
如果您使用的是 FormsAppCompatActivity,则可以使用
app:tabIndicatorColor="#FF3300" <!-- Set indicator color here, sets it to red-->
编辑
您需要创建一个自定义渲染器。
在 github 上查看此示例。
推荐阅读
- operating-system - 如何使一个solaris系统环境与另一个相同
- laravel - 保存多个项目多对多 Laravel 6
- javascript - 未捕获的 DOMException:无法在“FileReader”上执行“readAsDataURL”
- django - 模型中的 django unique_for 属性
- c++ - 如何识别用于构建工件(如在 mac 上构建的目标文件或二进制文件)的 xcode 版本和编译器版本?
- c# - 无法加载实体框架提供程序类型
- bash - 命令的 Lmod bash 补全
- mongodb - 这个 URL 地址的第一部分 'mongodb://localhost:27017/conFusion' 有什么作用?
- django - 获取 Django 对象上的所有相关集合对象,包括那些尚未持久化到数据库的对象
- php - 如果不使用作为变量,对象创建将不起作用