- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我需要为我的应用程序中的不同标签指定不同的 FontFamily。我需要使用默认字体(例如 Android 的 Roboto 和 iOS 的 Helvetica)及其修改(例如 Light、Medium、Bold)。据我所知,我应该使用 Roboto-Light 和 Helvetica-Light 来获得字体的 Light 版本(Medium 和 Bold 也一样)。除了这个要求之外,我还需要在 XAML 中设置字体(比如 described in documentation )所以我最终得到了这段代码
<StackLayout BackgroundColor="#F8F8F8" Padding="0, 20, 0, 0">
<Label Text="Black" TextColor="#000000" >
<Label.FontSize>
<OnPlatform x:TypeArguments="x:Double"
iOS="17"
Android="16"
WinPhone="16" />
</Label.FontSize>
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<OnPlatform.iOS>Helvetica-Black</OnPlatform.iOS>
<OnPlatform.Android>Roboto-Black</OnPlatform.Android>
<OnPlatform.WinPhone></OnPlatform.WinPhone>
</OnPlatform>
</Label.FontFamily>
</Label>
<Label Text="Light" TextColor="#000000">
<Label.FontSize>
<OnPlatform x:TypeArguments="x:Double"
iOS="17"
Android="16"
WinPhone="16" />
</Label.FontSize>
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<OnPlatform.iOS>Helvetica-Light</OnPlatform.iOS>
<OnPlatform.Android>Roboto-Light</OnPlatform.Android>
<OnPlatform.WinPhone></OnPlatform.WinPhone>
</OnPlatform>
</Label.FontFamily>
</Label>
<Label Text="Medium" TextColor="#000000" >
<Label.FontSize>
<OnPlatform x:TypeArguments="x:Double"
iOS="17"
Android="16"
WinPhone="16" />
</Label.FontSize>
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<OnPlatform.iOS>Helvetica-Medium</OnPlatform.iOS>
<OnPlatform.Android>Roboto-Medium</OnPlatform.Android>
<OnPlatform.WinPhone></OnPlatform.WinPhone>
</OnPlatform>
</Label.FontFamily>
</Label>
<Label Text="Bold" TextColor="#000000">
<Label.FontSize>
<OnPlatform x:TypeArguments="x:Double"
iOS="17"
Android="16"
WinPhone="16" />
</Label.FontSize>
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<OnPlatform.iOS>Helvetica-Bold</OnPlatform.iOS>
<OnPlatform.Android>Roboto-Bold</OnPlatform.Android>
<OnPlatform.WinPhone></OnPlatform.WinPhone>
</OnPlatform>
</Label.FontFamily>
</Label>
然而,Android 中的结果却出人意料。不同 Label 的 FontFamily 没有变化。它们看起来都一样。
iOS 中的相同代码按预期工作
我的问题是:如何在我的 Android 应用程序中获取 Roboto-Light、Roboto-Medium 和 Roboto-Bold 字体,如果遵循XAMARIN 文档不起作用?
最佳答案
更新:
我没有看到您第一次使用 API 18/4.3(在您的模拟器的标题栏中),以为您将它们加载为旧 android 版本的自定义 Assets 。由于 roboto 是自 4.1 以来的默认字体,您可以将它们用作:
原文:
https://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/fonts/
Xamarin.Forms for Android does not currently expose the ability to set the font to a custom font file, so custom renderers are required. When writing the renderer for the Android platform, create a Typeface instance that references a custom font file that has been added to the Assets directory of the application (with Build Action: AndroidAsset).
[assembly: ExportRenderer (typeof (MyLabel), typeof (MyLabelRenderer))]
namespace WorkingWithFonts.Android {
public class MyLabelRenderer : LabelRenderer {
protected override void OnElementChanged (ElementChangedEventArgs<Label> e) {
base.OnElementChanged (e);
var label = (TextView)Control; // for example
Typeface font = Typeface.CreateFromAsset (Forms.Context.Assets, "SF Hollywood Hills.ttf");
label.Typeface = font;
}
}
}
关于android - XAMARIN:跨平台 FontFamily,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32732381/
我正在开发一组应用程序,它们协同工作以创建一个用于处理计量数据的系统。我想让它们松散耦合有几个原因,并且系统应该可以由第三方扩展,因此应用程序将通过消息传递绑定(bind)在一起。 我正在寻找一种消息
如果我使用 python 2.6 和 Qt 为 windows 创建一个 gui,然后想在 solaris 或 linux 世界中运行。 我在两个系统上都需要什么,我猜两个平台都需要 2.6 和 Qt
我正在运行 Linux Ubuntu 10.04,我有一台 Windows 7 机器和一台运行 Mac OS X 10.6.4 的 MacBook。我如何编写一个简单的 C 程序(如 不是 QT!),
前言 今天给大家分享一个.NET开源(MIT License)、免费、跨平台(适用于 Windows、MacOS 和 Linux )、使用简单的面部识别库:FaceRecognitionDotNet
我知道汇编语言通常不是跨平台的。即使使用像 NASM 这样的东西,对于不同的架构和平台,您仍然需要不同的代码,这些架构和平台具有不同的运行时和诸如中断之类的东西的实现。但是如果有人因为喜欢汇编语言而想
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 8年前关闭。 Improve thi
This question already has answers here: How to play audio? (20个答案) 12天前关闭。 我正在编写一个dhtml应用程序,该应用程序创建系
我正在使用MonoGame开发一款游戏,该游戏使用SoundEffectInstance来实现游戏中的音效。在可以创建的SoundEffect实例数量以及可以同时播放的最重要实例方面,不同平台受到什么
如何在 java 中找到并运行默认计算器而不使我的程序依赖于平台。我可以对每个主要操作系统的所有路径进行硬编码,然后找到该人正在使用的操作系统,然后使用该操作系统各自的路径。但是,我不想那样做,有没有
有没有办法使用捏合来放大共享的Xamarin Forms,我只找到了每个平台的实现。 最佳答案 您可以使用 Pan Gesture 来实现它。这里有一个很好的在 PanContainer 中包装图像的
是否有最好/好的方法来同时为 Android 和 iOS(以及 Mac OS X)开发跨平台应用程序,例如游戏? 只是简单地开发一个仅使用 OpenGL 和 C/C++ 的应用程序应该很简单,不是吗?
我想知道 CSS 行为是否会随着操作系统的不同而变化。我的 css 对于 vista 和 win xp proffesional 对于相同版本的浏览器来说有点不同。我在 vista + ie8 和 x
我需要一种跨平台的方式来检查给定的文件路径是否是绝对的而不使用Pathname 库。为此,我唯一希望依赖的库是 File。它需要跨平台和跨实现,因此无论是 Ruby MRI、JRuby、Rubiniu
我正在尝试寻找一种跨平台的方法来从文件末尾删除 X 字节。 目前我发现: 特定于平台的解决方案(例如 truncate for posix):这是我不想要的,因为我希望 C++ 程序可以在多个平台上运
我想将可执行文件从一个目录复制到另一个目录。 源目录包括各种我不关心的文件(构建工件)。我只想使用适用于 OS X 和 Linux 的 bash 脚本获取可执行文件。 可执行文件是指具有可执行权限的文
我需要能够在服务器端处理简单 HTTP GET/PUT 请求的库。有一些特殊要求: 应该是跨平台的(这是主要因素) 支持多线程。 高性能 支持 HTTPS 许可证应允许链接专有代码(LGPL、BSD)
我正在寻找一种可用于从 Windows 和 Mac OSX 计算机上传大型 (~2GB) 文件的技术。应该可以根据请求/错误暂停和恢复上传。具有基本计算机技能的用户应该可以轻松安装最终产品。 我正在考
我正在寻找一种使用 java 播放 .flv 文件的方法。这意味着我需要一个跨平台的 ffmpeg 库。我一直在玩弄 jmf 和 fobs4jmf,但我无法在 linux 中播放,因为我需要一个本地库
我想在基于浏览器的应用程序中做的一件事是允许用户选择一些文本(不是在 中,只是普通的文本!),然后让我的应用程序弹出一个然后可以与下一个交互的小工具栏(在我的例子中,添加注释)。 我在 google
对于 PyInstaller 中的新功能,我们需要一个命令行选项来接收其中包含任何分隔符的字符串。这是讨论:https://github.com/pyinstaller/pyinstaller/pul
我是一名优秀的程序员,十分优秀!