xamarin - AndroidX 中的 Xamarin Forms 5.0 TabbedPage 选项卡标题文本自定义
问题描述
我正在开发 Xamarin Forms 应用程序。要求是将标签页的标题设置为字母大小写 + 使用自定义字体。
正如您在本文中看到的那样,我发现了一些解决方案,其中需要在文件 Resources/layout/Tabbar.xml 中更改样式以实现所需的结果。
但是,不幸的是 Xamarin Forms 5.0 使用 AndroidX 并从默认创建中删除了资源/布局目录。并且还从 Android 项目的 MainActivity.cs 中删除了这两行代码:
TabLayoutResource = Resource.Layout.Tabbar; // Removed in AndroidX and Xamarin Forms Ver 5.0
ToolbarResource = Resource.Layout.Toolbar; // Removed in AndroidX and Xamarin Forms Ver 5.0
正如您在 Xamarin 官方文档中看到的那样
现在我很好奇如何使用 AndroidX 在更新的 XAMARIN FORMS 版本 5.0 中对 TabbedPage 标题文本进行自定义样式?任何想法?
解决方案
您应该将 保留 TabLayoutResource = Resource.Layout.Tabbar;
在您的 MainActivity 中。
之Tabbar.xml
类的:
<com.google.android.material.tabs.TabLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
...
app:tabTextAppearance="@style/MyCustomTextAppearance" //make your title to Letter-Case
/>
然后定义MyCustomTextAppearance
你的风格Resources/styles
<style name="MyCustomTextAppearance" parent="TextAppearance.Design.Tab">
<item name="textAllCaps">false</item>
</style>
推荐阅读
- python - 这些 `.` 属性绑定在 `functools.partial` 的实现中是必需的吗?
- ruby - 如何编写具有多种可能结果的场景
- azure - Azure Function 无法加载 ApplicationInsights 程序集
- asp.net - 将旧的 ASP url 重定向到新的 Wordpress 页面
- python - 无法使用 XPath 从网页获取价格
- python - 为什么调整模态 Qt 对话框的大小使其不再停留在 ctwm 窗口管理器中其父级的顶部?
- python - 使用 lambda 调用带有参数但传递索引而不是项的函数
- google-apps-script - 如何将 drive.file 范围用于独立的谷歌应用程序脚本
- linux - 当我在 Windows 中编辑代码但在 Linux 中构建和运行代码时如何使用 git 进行版本控制(使用 pycharm)
- python - 为什么 numpy.cumsum 的最后一个条目不一定等于 numpy.sum