hanki.dev

Compose TalkBack: read string one character at a time

Sometimes TalkBack reads number id's as a large number. For example, if you have text 876234345 on screen it might read it as eight hundred seventy-six million, two hundred thirty-four thousand, three hundred forty-five instead of eight seven six two three four three four five.

To fix this, add space between every character and TalkBack will read it one character at a time!

fun getTalkBackString(str: String): String {
    return str.replace(".".toRegex(), "$0 ")
}

Then override the semantics with Modifier.

Text(
    text = "ID: $id",
    modifier = Modifier.semantics {
        this.contentDescription = "ID: ${getTalkBackString(id)}"
    }
)

✌🏼 Like my content? Subscribe via RSS feed.