Furigana with Jetpack Compose

219 Views Asked by At

I am trying to show furigana (small text helping for pronunciation) above kanji using Jetpack Compose.
I have searched on the Web but all tools are designed to be used with Java.

2

There are 2 best solutions below

1
Joel Handwell On BEST ANSWER

You can use Android Compose Furigana to put furigana on text.

Here is how to use it:

  1. Add dependency in Gradle build file
    dependencies {
        implementation 'com.github.mainrs:android-compose-furigana:1.0.0'
    }

Or, in Gradle Kotlin DSL

    dependencies {
        implementation("com.github.mainrs:android-compose-furigana:1.0.0")
    }
  1. Declare composable furigana text
    import net.zerotask.libraries.android.compose.furigana.TextData
    import net.zerotask.libraries.android.compose.furigana.TextWithReading
    
    @Composable
    internal fun Content(){
        val textContent = listOf(
            TextData(text = "これは")
            TextData(text = "漢字", rading = "かんじ")
            TextData(text = "です")
        )
        TextWithReading(textContent = textContent, showReadings = true)
    }
0
mainrs On

Author of the library here. There are still some shortcomings that I could not solve that probably involve tinkering around with TextLayout. Specifically, the text is not split at good positions. Compared to Text, which splits at positions that make sense grammatically.