Skip to content

Instantly share code, notes, and snippets.

@rahulkhatri19
Created March 24, 2024 09:38
Show Gist options
  • Save rahulkhatri19/c1ca2db50325a8b4de65c36dbcfb32ed to your computer and use it in GitHub Desktop.
Save rahulkhatri19/c1ca2db50325a8b4de65c36dbcfb32ed to your computer and use it in GitHub Desktop.
package `in`.rahul.jetpackex
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shadow
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import `in`.rahul.jetpackex.ui.theme.JetpackExTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
JetpackExTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Column {
TextBasic("Android")
TextShadow("Android")
TextGradient("Android")
}
}
}
}
}
}
@Composable
fun TextGradient(name: String, modifier: Modifier = Modifier) {
val gradientColor = listOf(Color.Cyan, Color.Magenta, Color.Blue)
Text(
text = "Hello $name! Welcome to Jetpack compose Text update video. Here we are adding Gradient to our Greeting Text.",
modifier = modifier.padding(8.dp, 8.dp, 8.dp, 8.dp),
fontSize = 24.sp,
fontWeight = FontWeight.Bold,
style = TextStyle(
brush = Brush.linearGradient(colors = gradientColor)
)
)
}
@Composable
fun TextShadow(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name! This is Jetpack compose Text shadow and blur",
modifier = modifier.padding(8.dp, 8.dp, 8.dp, 8.dp),
fontSize = 24.sp,
fontWeight = FontWeight.Bold,
style = TextStyle(
shadow = Shadow(
color = Color.Blue, offset = Offset(5.0f, 10.0f), blurRadius = 3f
)
),
)
}
@Composable
fun TextBasic(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name! This is Jetpack compose Text Basic Modification.",
modifier = modifier.padding(8.dp, 8.dp, 8.dp, 8.dp),
fontSize = 24.sp,
fontWeight = FontWeight.Bold,
color = Color.Blue,
)
}
@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
JetpackExTheme {
TextBasic("Android")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment