Android Compose – Change Text Color

To change color of Text composable in Android Jetpack Compose, pass a required Color value for the optional color parameter of Text composable.

Text("Hello World!",
    color = Color.Red)

Text("Hello World!",
	color = Color(0, 100, 100))

Example

Create an Android Application with Jetpack Compose as template, and modify MainActivity.kt as shown in the following.

The Text composable in the following activity displays Hello World! text in red color.

MainActivity.kt

</>
Copy
package com.example.myapplication

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material.Text
import androidx.compose.ui.graphics.Color
import com.example.myapplication.ui.theme.MyApplicationTheme

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyApplicationTheme {
                Text("Hello World!",
                    color = Color.Red)
            }
        }
    }
}

Screenshot in Emulator

Android Compose - Change Text Color

We can also pass red, blue, green color components as arguments to Color(), to apply a custom color to Text composable.

MainActivity.kt

</>
Copy
package com.example.myapplication

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material.Text
import androidx.compose.ui.graphics.Color
import com.example.myapplication.ui.theme.MyApplicationTheme

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyApplicationTheme {
                Text("Hello World!",
                    color = Color(0, 100, 100))
            }
        }
    }
}

Screenshot in Emulator

Android Compose - Change Text Color

Conclusion

In this Android Jetpack Compose Tutorial, we learned how to change the color of Text composable in Android Project with Jetpack Compose.