Search code examples
androidkotlinandroid-jetpack-composeandroid-compose-textfield

How do I fix the Text error in Android Studio without creating a function for this?


When ever I use the Text() function, it shows this error:

None of the following functions can be called with the arguments supplied.
Text(AnnotatedString, Modifier = ..., Color = ..., TextUnit = ..., FontStyle? = ..., FontWeight? = ..., FontFamily? = ..., TextUnit = ..., TextDecoration? = ..., TextAlign? = ..., TextUnit = ..., TextOverflow = ..., Boolean = ..., Int = ..., Int = ..., Map<String, InlineTextContent> = ..., (TextLayoutResult) → Unit = ..., TextStyle = ...)

I tried to create a seperate function for this, but the text field does not get executed:

fun Text(s: String, Style: TextStyle) {

}

Although errors get removed by using seperate functions.


Solution

  • You are attempting to override a NEW "Text" function, which cannot be overridden. If you want to create a new Text, try using this code.

    @Composable
    fun MyText(s: String, style: TextStyle) {
    Text(text = s, style = style) }