androidkotlinandroid-jetpack-composekanji

Furigana with Jetpack Compose


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.


Solution

  • 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)
        }