MainActivity.kt
package com.cfsuman.jetpackcompose
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MainContent()
}
}
@Composable
fun MainContent(){
val isGreen = remember { mutableStateOf(value = true) }
val animatedColor = animateColorAsState(
targetValue = if (isGreen.value) Color(0xFF7BB661)
else Color(0xFFCC5500),
animationSpec = tween(durationMillis = 5000)
)
Column(
modifier = Modifier
.fillMaxSize()
.background(Color(0xFFF1DDCF))
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Button(
onClick = { isGreen.value = !isGreen.value }
) {
Text(text = "Animate Color Change")
}
Box(
modifier = Modifier
.fillMaxWidth()
.height(250.dp)
.background(animatedColor.value)
.clip(RoundedCornerShape(16.dp))
)
}
}
@Preview
@Composable
fun ComposablePreview(){
//MainContent()
}
}
- jetpack compose - animateFloatAsState
- jetpack compose - Animation finished listener
- jetpack compose - Tween animation
- jetpack compose - Keyframes animation
- jetpack compose - IconButton from vector resource
- jetpack compose - ViewModel Room delete clear data
- jetpack compose - flowOf flow builder
- jetpack compose - Kotlinx serialization parse to json element
- jetpack compose - Kotlinx serialization pretty print
- jetpack compose - How to change NavigationBar color
- jetpack compose - Long click listener
- jetpack compose - Navigation arguments data type
- jetpack compose - Snackbar host state
- jetpack compose - TopAppBar navigation
- jetpack compose - Card shadow