【问题标题】:XAMARIN - is it possible to use default/system fonts in my app?XAMARIN - 是否可以在我的应用程序中使用默认/系统字体?
【发布时间】:2021-05-15 11:55:55
【问题描述】:

我浏览了我的 3 台 Android 设备(SGS6、SGS20、H10)上的“/system/fonts”文件夹,将所有文件从那里下载到我的电脑上,分析后发现某些字体名称对所有 3 台设备都是通用的 - AndroidClock, Carrois Gothic SC, Coming Soon, Cutive Mono, Dancing Script, Droid Sans Mono, Noto Naskh, Noto Sans, Noto Serif, Roboto, Roboto Black, Roboto Condensed, Roboto Condensed Light, Roboto Light, Roboto Medium, Roboto Thin。

问题 - 是否可以在我的 Xamarin 应用程序中使用其中任何一个而无需明确绑定它们? 如果我只是指定 myLabel.FontFamily = "Coming Soon" 并且这样会很好......但实际上这根本不起作用。 :-( 所以,我有点困惑——为什么?如果可能的话,让它以某种方式工作?...

我尝试在我的 Xamarin 应用程序中显示 10 个标签,所有标签都具有不同的 FontFamily 名称:AndroidClock、Carrois Gothic SC、Coming Soon、Cutive Mono、Dancing Script、Droid Sans、Droid Serif、Droid Sans Mono - 但所有标签都显示为相同的字体(我什至不确定默认字体的名称是什么)。

我需要它仅适用于 Android。对iOS完全不感兴趣。 有没有办法告诉 Xamarin 在设备上只使用可用的系统字体?

【问题讨论】:

    标签: android xamarin fonts


    【解决方案1】:

    如果我只是指定 myLabel.FontFamily = "Coming Soon" 并且这样会很好......但实际上这根本不起作用。 :-( 所以,我有点困惑——为什么?如果可能的话,让它以某种方式工作?...

    如果你解析fonts.xml文件,你可以找到哪个字体系列使用哪个字体(见here):

    ╔════╦════════════════════════════╦═════════════════════════════╗
    ║    ║ FONT FAMILY                ║ TTF FILE                    ║
    ╠════╬════════════════════════════╬═════════════════════════════╣
    ║  1 ║ casual                     ║ ComingSoon.ttf              ║
    ║  2 ║ cursive                    ║ DancingScript-Regular.ttf   ║
    ║  3 ║ monospace                  ║ DroidSansMono.ttf           ║
    ║  4 ║ sans-serif                 ║ Roboto-Regular.ttf          ║
    ║  5 ║ sans-serif-black           ║ Roboto-Black.ttf            ║
    ║  6 ║ sans-serif-condensed       ║ RobotoCondensed-Regular.ttf ║
    ║  7 ║ sans-serif-condensed-light ║ RobotoCondensed-Light.ttf   ║
    ║  8 ║ sans-serif-light           ║ Roboto-Light.ttf            ║
    ║  9 ║ sans-serif-medium          ║ Roboto-Medium.ttf           ║
    ║ 10 ║ sans-serif-smallcaps       ║ CarroisGothicSC-Regular.ttf ║
    ║ 11 ║ sans-serif-thin            ║ Roboto-Thin.ttf             ║
    ║ 12 ║ serif                      ║ NotoSerif-Regular.ttf       ║
    ║ 13 ║ serif-monospace            ║ CutiveMono.ttf              ║
    ╚════╩════════════════════════════╩═════════════════════════════╝
    

    因此,ComingSoon.ttf 在 FontFamily 中被称为 casual

    <Label Text="Hello monospace!"
            FontFamily="monospace"
            HorizontalOptions="CenterAndExpand" />
    <Label Text="ComingSoon"
            HorizontalOptions="CenterAndExpand"
            FontFamily="casual"/>
    <Label Text="Roboto Black"
            HorizontalOptions="CenterAndExpand"
            FontFamily="sans-serif-black"/>
    <Label Text="Default Font"
            HorizontalOptions="CenterAndExpand" />
    

    效果:

    这里是the related discuusion

    【讨论】:

      【解决方案2】:

      来自Fonts in Xamarin Forms

      显示文本的控件可以将 FontFamily 属性设置为字体 姓氏,例如“Times Roman”。但是,这只有在 特定平台支持该字体系列。

      有许多技术可以用来尝试推导 平台上可用的字体。但是,存在 TTF(True Type Format)字体文件并不一定意味着字体 家庭,并且通常包含不打算用于 应用程序。另外,平台上安装的字体可以 随平台版本而变化。所以最靠谱的方法 指定字体系列是使用自定义字体。

      【讨论】:

        猜你喜欢
        • 2015-05-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-10
        • 2020-01-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多