Android Compose – Create Text Composable

To create new Text in Android Jetpack Compose, use Text composable. Pass the text to display, as string argument to Text() function.

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.

MainActivity.kt

package com.example.myapplication

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

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

Screenshot in Emulator

ADVERTISEMENT
Android Compose - Create Text Composable

Conclusion

In this Android Jetpack Compose Tutorial, we learned how to create a Text composable in Android Project with Jetpack Compose.