Android Jetpack Compose – Text Color
To set a specific color for the text in Text composable in Android Jetpack Compose, you can set the color parameter of the Text composable with the required Color (androidx.compose.ui.graphics.Color) value.
Example
In the following example, we have set the color of the Text composable to Color.Blue.
MainActivity.kt
package com.example.myapplication
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.sp
import com.example.myapplication.ui.theme.MyApplicationTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyApplicationTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Text(
text = "Hello Android!",
fontSize = 50.sp,
color = Color.Blue
)
}
}
}
}
}
Screenshot
Now, let us change the color to a Color value with specific red, green, and blue components.
Text(
text = "Hello Android!",
fontSize = 50.sp,
color = Color(red=0.1f, green = 0.8f, blue = 0.0f)
)
Screenshot
Summary
In this tutorial, we have seen how to set the color of Text composable in Android Jetpack Compose, using color parameter of Text composable.