roku - Roku:BrightScript:如何为标签设置自定义字体和颜色?
问题描述
我正在尝试为标签设置自定义字体,但它不起作用,不知道这样做的正确方法是什么。
创建标签.brs
font = CreateObject("roSGNode", "Font")
font.uri = "pkg:/fonts/GothamMedium.ttf"
font.size = "24"
m.top.setFocus(true)
m.label1 = m.top.findNode("label1")
m.label1.font.size = 20
m.label1.text = "Hello"
' m.label1.font = font -> if uncommented, then text doesn't show up
m.label1.color="0x72D7EEFF"
end function
m.label1.font = 字体 // 不工作
创建标签.xml
<?xml version="1.0" encoding="utf-8"?>
<component name="CreateLabel" extends="Scene">
<interface>
<field id="label1" type="string" />
</interface>
<script type="text/brightscript" uri="pkg:/components/CreateLabel/CreateLabel.brs" />
<script type="text/brightscript" uri="pkg:/source/Main.brs" />
<children>
<Label
id="label1"
text="Narendra"
width="200"
height="100"
horizAlign="center"
vertAlign="center"
/>
</children>
</component>
解决方案
你可以试试这个-
代替
font.size = "24"
尝试
font.size = 24
即字体大小应该是整数。在下面的行评论 -
'm.label1.font.size = 20
取消注释此行 -
m.label1.font = font
它应该工作。颜色设置看起来不错。
或者,如果你想在 xml 中设置字体,你可以尝试这样的 -
<Label
id="label1"
text="Narendra"
width="200"
height="100"
horizAlign="center"
vertAlign="center" >
<Font role = "font" uri = "pkg:/fonts/GothamMedium.ttf" size = "24" />
</Label>
请注意,每个属性的(字段/属性)值都将在 xml 文件(甚至整数)中用双引号引起来,但 brs 文件并非如此。还要确保字体文件 (GothamMedium.ttf) 在上述路径 (pkg:/fonts/GothamMedium.ttf) 中可用。
推荐阅读
- function - 查询寄存器数据时批处理脚本中的数据同步问题,我需要 RegFlushKey 之类的东西,但需要批量处理
- c# - C# Winforms:无法使用 system.windows 创建窗口
- python - Python 告诉我我的 if 语句包含语法错误
- excel - 嵌套的 For/Do While/While 无法到达 VBA/Macro 中的外循环
- javascript - 尝试替换 div img src 时 Jquery attr 不起作用
- javascript - 使用带有变量的 querySelector 来获取单选按钮值
- python - 检查特定python模块的实例
- java - Java:如何将数组中的所有元素四舍五入到小数点后两位?
- java - Apache-POI:创建电子表格时如何设置单元格的背景颜色?
- reactjs - 如何在反应中使用 D3.js