【问题标题】:Xamarin Forms 5.0 TabbedPage Tab Title Text Customization in AndroidXAndroidX 中的 Xamarin Forms 5.0 TabbedPage 选项卡标题文本自定义
【发布时间】:2021-10-07 19:25:57
【问题描述】:

我正在开发 Xamarin 表单应用程序。要求是使标签页标题为字母大小写+使用自定义字体。

正如您在this 文章中看到的那样,我找到了一些解决方案,其中需要在文件 Resources/layout/Tabbar.xml 中更改样式以达到所需的结果。

但是,不幸的是 Xamarin Forms 5.0 使用 AndroidX 并从默认创建中删除了资源/布局目录。并且还从 Android Project 的 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 官方文档here中看到

现在我很好奇如何使用 AndroidX 在更新的 XAMARIN FORMS 5.0 版中对 TabbedPage 标题文本进行自定义样式?有什么想法吗?

【问题讨论】:

    标签: xamarin xamarin.forms xamarin.android androidx tabbedpage


    【解决方案1】:

    如果您阅读了链接到的文章,如果您正在自定义外观,它不会告诉您将其删除。在这种情况下,您应该编辑布局以改用 AndroidX 类型。

    因此,如果您想自定义布局,则需要将 androidx.appcompat.widget.Toolbar 用于布局中的 Toolbar,而将 com.google.android.material.tabs.TabLayout 用于 TabLayout。

    【讨论】:

    • “不工作”是什么意思?你有没有收到任何错误信息,外观没有改变,或者别的什么?我无法从您的评论中阅读您的意图。
    • 外观没有变化
    • 好吧,如果你不提供你正在使用的布局,这还不清楚
    • 由于 stackoverflow 的信誉点较少,无法插入有问题的图像
    • 不要使用图片,直接在问题中添加代码即可。
    【解决方案2】:

    您应该在 MainActivity 中保留 TabLayoutResource = Resource.Layout.Tabbar;

    还有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 
    
    />
    

    然后在您的Resources/styles 中定义MyCustomTextAppearance 样式

    <style name="MyCustomTextAppearance" parent="TextAppearance.Design.Tab">
         <item name="textAllCaps">false</item>
    </style>
    
     
    

    【讨论】:

    • 已申请。对外观没有影响。
    • @FahadAliQureshi 它适用于我,字母从大写到大小写。
    • 您使用的是哪个 Xamarin Forms 版本?
    • @FahadAliQureshi 我使用的是 5.0.0.2083 版本。
    猜你喜欢
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 2018-05-29
    • 1970-01-01
    • 1970-01-01
    • 2020-02-26
    • 1970-01-01
    相关资源
    最近更新 更多