【问题标题】:Unable to apply Helvetica Neue Light Font family on button text in android无法在 android 的按钮文本上应用 Helvetica Neue Light Font 系列
【发布时间】:2016-10-17 09:45:23
【问题描述】:

我在 xamarin 表单中应用了如下所示的按钮属性。它在 iOS 上运行良好,但在 android 上会出现问题。

    Button anyButton = new Button ();
    anyButton.Text = "Men";
    anyButton.FontFamily = "HelveticaNeue-Light" ;
    anyButton.FontSize = 16;
    anyButton.TextColor = Color.Black;
    anyButton.FontAttributes = FontAttributes.None;

附上具有相同属性的相同视图的屏幕截图。与 iOS 相比,Android 中的按钮文本看起来有点粗体。 我尝试通过为 Android 创建按钮渲染器并将属性指定为

    Typeface fontStyle = Typeface.Create("HelveticaNeue-Light", TypefaceStyle.Normal);
    Control.SetTextColor(Android.Graphics.Color.ParseColor(Colors.BLACK_COLOR));
    Control.SetTextSize(Android.Util.ComplexUnitType.Sp, 16);
    Control.Typeface = fontStyle;

但仍然面临无法在 android 中的按钮文本上应用“浅色”字体的问题。

Android

iOS

【问题讨论】:

    标签: xamarin.android xamarin.forms custom-font font-family


    【解决方案1】:

    Android 没有“helvetica”字体。他们的替代品是 Roboto,(Helvetica Alternative in Android)

    你可以试试

    Device.OnPlatform(...)
    

    请致电 (https://developer.xamarin.com/api/member/Xamarin.Forms.Device.OnPlatform/) 他们甚至在 API 文档中提供了一个使用字体的示例。

    选择此选项,或者您需要尝试使用自定义渲染器并下载类似于 helvetica 的字体。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-25
      • 2013-08-07
      • 1970-01-01
      • 2017-10-22
      • 1970-01-01
      • 2020-04-08
      • 1970-01-01
      相关资源
      最近更新 更多