Sanyam Jain
Sanyam Jain

Reputation: 1

I am having issue in the Text Compossable

Every time I write the code the red line comes under the Text compossable method. which states

Text(AnnotatedString, Modifier = ..., Color = ..., TextUnit = ..., FontStyle? = ..., FontWeight? = ..., FontFamily? = ..., TextUnit = ..., TextDecoration? = ..., TextAlign? = ..., TextUnit = ..., TextOverflow = ..., Boolean = ..., Int = ..., Map<String, InlineTextContent> = ..., (TextLayoutResult) → Unit = ..., TextStyle = ...) defined in androidx.compose.material3

My code:

fun Greeting( one: String, two: String, three: String, four: String, modifier: Modifier = Modifier) {
    Column(Modifier.fillMaxWidth()) {
        Row(Modifier.weight(1f)) {
            Column(
                modifier = modifier
                    .fillMaxSize()
                    .padding(16.dp),
                horizontalAlignment = Alignment.CenterHorizontally,
                verticalArrangement = Arrangement.Center
            ) {
                Text(
                    text = one,
                    fontWeight = FontWeight.Bold,
                    backgroundColor = Color.Green,
                    modifier = Modifier
                        .padding(bottom = 16.dp)
                        .weight(1f)

                )
                Text(
                    text = two,
                    fontWeight = FontWeight.Bold,
                    backgroundColor = Color.Yellow,

                    modifier = Modifier.weight(1f)
                )
            }
        }
        Row(Modifier.weight(1f)) {
            Column(
                modifier = modifier
                    .fillMaxSize()
                    .padding(16.dp),
                horizontalAlignment = Alignment.CenterHorizontally,
                verticalArrangement = Arrangement.Center
            ) {
                Text(
                    text = three,
                    fontWeight = FontWeight.Bold,
                    backgroundColor = Color.Cyan,
                    modifier = Modifier
                        .weight(1f)
                        .padding(bottom = 16.dp)
                )
                Text(
                    text = four,
                    fontWeight = FontWeight.Bold,
                    backgroundColor = Color.LightGray,

                    modifier = Modifier.weight(1f)
                )
            }
        }
    }
}

Greeting(stringResource(id = R.string.one),stringResource(id = R.string.two),stringResource(id = R.string.three), stringResource(id = R.string.four))
    

I am unable to remove the red line under in text composable.

Upvotes: 0

Views: 275

Answers (1)

Christian Miranda
Christian Miranda

Reputation: 66

 backgroundColor = Color.LightGray,

This is the reason why there's a red line in text composable.

You can simply remove it.

If you want to add a background color, you can put your text composable in Card composable or Box composable, or wherever you need, and modify their backgroundColor.

If you want to modify the textColor, you can modify this, and set in the style of your text composable.

    @Composable
fun defaultStyle(
    color: Color = Color.Black,
    fontWeight: FontWeight = FontWeight.Normal,
    fontSize: TextUnit = MaterialTheme.typography.body2.fontSize
): TextStyle {
    return MaterialTheme.typography.body2.copy(
        color = color,
        fontWeight = fontWeight,
        fontSize = fontSize
    )
}

Hope this helps.

Upvotes: 1

Related Questions