Adding text in android is we were using TextView in android studio.
But using jetpack compose we don't need TextView as a deign layout.
Yes , using Jetpack Compose we can add text only with coding so lets start how its work ,
First you have to add some dependency library in your build.gradle (app module)
implementation 'androidx.compose.ui:ui:1.0.0'
implementation 'androidx.compose.material:material:1.4.3'
implementation 'androidx.compose.material:material-icons-core:1.4.3'
implementation 'androidx.constraintlayout:constraintlayout-compose:1.0.0-beta02'
debugImplementation 'androidx.compose.ui:ui-tooling:1.4.3'
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha07
implementation 'androidx.navigation:navigation-compose:2.4.0-alpha08'
Then in your MainActivity.kt
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.material.Text
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//setContentView(R.layout.activity_main)
setContent {
Text("Text from Jetpack Compose")
}
}
}
So , This is the how we can add text in android using Jetpack Compose.
No comments:
Post a Comment
Comments