DEPRECATION NOTICE: This entire page documents the legacy Text
manipulation system. For new projects: Use Data Binding instead. For existing projects: Plan to
migrate from direct text run manipulation to Data Binding as soon as possible.
For more information on designing and animating Text, please refer to the editor’s text section:
Read/Update Text Runs at Runtime
⚠️ LEGACY CONTENT WARNING: The following sections document the deprecated
Text manipulation system. This content is provided for legacy support
only. New implementations should use Data Binding.
If you intend to update a text run at runtime it’s important to manually enter a unique name for the run in the editor:
And then export the name: right-click and select Export name
You can identify an exported component if it’s surrounded by square brackets. This makes it possible for the run to be “discoverable” at runtime by its name. For more information, see Exporting for Runtime.
If the name is not set manually in the editor the name will not be part of
the exported .riv (to reduce file size).
Reading Text via RiveAnimationView
To read a given text run text value at any given time, reference the .getTextRunValue() API on the RiveAnimationView:
fun getTextRunValue(textRunName: String): String? = try
Supply the text run name and you’ll have the Rive text run value returned, or null if the text run could not be queried.
Setting Text via RiveAnimationView
To set a given text run value at any given time, reference the .setTextRunValue() API on the RiveAnimationView:
fun setTextRunValue(textRunName: String, textValue: String)
Supply the text run name and a second parameter, textValue, with a String value that you want to set the new text value for.
If the supplied textRunName Rive text run cannot be queried on the active artboard, Rive will throw a RiveException that you may need to catch and handle gracefully in your application.
Reference to Rive TextRun
You can also choose to query the active Artboard for the Rive text run reference and get/set a text property manually.
private val textRun by lazy(LazyThreadSafetyMode.NONE) {
yourRiveAnimationView.artboardRenderer?.activeArtboard?.textRun("name")
}
Example Usage
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import app.rive.runtime.kotlin.RiveAnimationView
class DynamicTextActivity : AppCompatActivity(), TextWatcher {
private val animationView by lazy(LazyThreadSafetyMode.NONE) {
findViewById<RiveAnimationView>(R.id.dynamic_text)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.dynamic_text)
val editText = findViewById<EditText>(R.id.text_run_value)
editText.addTextChangedListener(this)
}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
// get the current value of the reference
animationView.getTextRunValue("name")
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
// update the reference
animationView.setTextRunValue("name", s.toString())
}
}
Read/Update Nested Text Runs at Runtime
⚠️ DEPRECATED FEATURE: Nested Text Runs are part of the legacy Text
manipulation system. Use Data Binding instead for controlling component
text properties at runtime.
It’s possible to set nested text runs at runtime—text that is not on the main artboard but on a Component. To set a nested text run, you’ll need to take note of the path where the input exists at an artboard level.
For example, to get/set the text run named button_text on the Button artboard, you need to provide the correct path.
Setting Nested Text Runs
The artboard names here are:
- Main -> NestedArtboard -> Button
However, the path is determined based on the names set in the hierarchy:
- ArtboardWithUniqueName -> ButtonWithUniqueName
The path is then: ArtboardWithUniqueName/ButtonWithUniqueName
Be sure to mark the components and text runs as exported.
Export
component name
Do not use ”/” in the name for your components, as that will break the search
functionality at runtime.
Reading Text via RiveAnimationView
To read a given text run text value at any given time, reference the .getTextRunValue() API on the RiveAnimationView:
fun getTextRunValue(textRunName: String, path: String): String? = try
Supply the text run name and the path to where it exists and you’ll have the Rive text run value returned, or null if the text run could not be queried.
Setting Text via RiveAnimationView
To set a given text run value at any given time, reference the .setTextRunValue() API on the RiveAnimationView:
fun setTextRunValue(textRunName: String, textValue: String, path: String)
Supply the text run name, a second parameter, textValue, with a String value that you want to set the new text value for, and the path value to where the text run exists at an artboard level.
If the supplied textRunName Rive text run cannot be queried on the active artboard, Rive will throw a RiveException that you may need to catch and handle gracefully in your application.
Reference to Rive TextRun
You can also choose to query the active Artboard for the Rive text run reference and get/set a text property manually.
private val textRun by lazy(LazyThreadSafetyMode.NONE) {
yourRiveAnimationView.artboardRenderer?.activeArtboard?.textRun("name", "path/to/artboard")
}
Semantics for Accessibility
We recommend using Data Binding instead as
you’ll be able to do a two way text binding.
As Rive Text does not make use of the underlying platform text APIs, additional steps need to be taken to ensure it can be read by screen readers.
Please see the respective platform/SDKs developer documentation for additional information regarding accessibility concerns.