文本
⚠️ 已弃用:推荐使用数据绑定(Data Binding)替代直接操作文本运行(Text Run)。
文本运行(Text Runs)是 Rive 中用于 显示动态文本的元素。
通过 RiveAnimationView 读取文本
使用 RiveAnimationView 上的 .getTextRunValue() API 读取文本运行的值:
fun getTextRunValue(textRunName: String): String?
提供文本运行名称,将返回 Rive 文本运行的值;如果无法查询文本运行,返回 null。
通过 RiveAnimationView 设置文本
使用 RiveAnimationView 上的 .setTextRunValue() API 设置文本运行的值:
fun setTextRunValue(textRunName: String, textValue: String)
提供文本运行名称和 textValue 字符串参数来设置新的文本值。
如果提供的
textRunName无法在活动画板上查询到 Rive 文本运行,Rive 将抛出RiveException,你可能需要在应用中捕获并妥善处理。
引用 Rive TextRun
也可以查询活动画板获取 Rive 文本运行引用,然后手动获取/设置文本属性。
private val textRun by lazy(LazyThreadSafetyMode.NONE) {
yourRiveAnimationView.artboardRenderer?.activeArtboard?.textRun("name")
}