Saturday, 21 September 2024

Kotlin Jetpack Compose

In this i have created one main layout with green background ,and place a text inside for loop,added scrollView in Column

 @Composable

fun MainLayout() {
Column(
modifier = Modifier
.fillMaxSize()
.background(Color.Green)
.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.SpaceEvenly,
horizontalAlignment = Alignment.CenterHorizontally,
) {
for (i in 1..5)
Text(text = "Supriya")
}
}
}
2. Here we can create LazyColumn to have scrool automatically,
no need to add scrll attributes. 
@Composable
fun MainLayout() {
LazyColumn( modifier = Modifier
.background(Color.Magenta),
content = {
item {
for (i in 1..200)
Text(text = "Android"
, modifier = Modifier
.fillMaxWidth()
.padding(30.dp))
}
}
)
}


3. Play with Box-Layout it is same like FrameLayout. added 3
textview and one button with click amd showing Toast popup.
@Composable
fun MainLayout() {
Box(
modifier = Modifier
.fillMaxSize()
.padding(20.dp),
contentAlignment = Alignment.Center
) {
Text(
text = "Supriya",
color = Color.Red,
modifier = Modifier.align(Alignment.TopCenter)
)
Text(text = "Ankit", color = Color.Green, modifier = Modifier.align(Alignment.Center))
Text(
text = "Saurabh",
color = Color.Magenta,
modifier = Modifier.align(Alignment.BottomCenter)
)

Button(
onClick = {
Toast.makeText(this@MainActivity, "Button Click", Toast.LENGTH_LONG).show()
},
modifier = Modifier
.align(Alignment.CenterEnd)) {
Text(text = "ClickMe")

}
}
}








4. CardLayout in jetpack Compose
@Composable
fun MainLayout() {
Card(modifier = Modifier
.padding(horizontal = 8.dp, vertical = 10.dp)
.fillMaxWidth(),
elevation = CardDefaults.cardElevation(8.dp)) {
Image(
painter = painterResource(id = R.drawable.img_1),
contentDescription = null,
modifier = Modifier
.padding(8.dp)
.width(100.dp)
.height(100.dp)
.clip(RoundedCornerShape(CornerSize(4.dp)))
)
Text(text = "Supriya", modifier = Modifier
.align(Alignment.End)
.fillMaxWidth())
}
}

5. Change status bar color:
res->values->themes.xml
<resources>
<
style name="Theme.BAsicCompose1" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:statusBarColor">@color/lightPurple</item>
</
style>
</
resources>
res->values->colors.xml
<color name="lightPurple">#FFD0BCFF</color>

No comments:

Post a Comment

how to change status bar color in jectpack compose.

 Step1: Go to MainActivity and do following: enableEdgeToEdge ( statusBarStyle = SystemBarStyle .light( Color . Green .h...