MainActivity.kt
package com.cfsuman.jetpackcompose
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
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 kotlin.math.roundToInt
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MainContent()
}
}
@Composable
fun MainContent(){
val sliderPosition = remember { mutableStateOf(0f)}
val intPosition = (sliderPosition.value * 100).roundToInt()
Column(
Modifier
.background(Color(0xF5F5F5))
.fillMaxSize()
.padding(16.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
"$intPosition",
fontWeight = FontWeight.Bold,
fontSize = 25.sp
)
Slider(
value = sliderPosition.value,
onValueChange = { sliderPosition.value = it }
)
}
}
@Preview
@Composable
fun ComposablePreview(){
//MainContent()
}
}
- jetpack compose - How to use Switch
- jetpack compose - How to use Snackbar
- jetpack compose - Indeterminate LinearProgressIndicator
- jetpack compose - Indeterminate CircularProgressIndicator
- jetpack compose - LinearProgressIndicator example
- jetpack compose - CircularProgressIndicator example
- jetpack compose - How to use TopAppBar
- jetpack compose - How to use BottomAppBar
- jetpack compose - BottomAppBar with FAB example
- jetpack compose - Circle shape example
- jetpack compose - Cut corner shape example
- jetpack compose - Image from drawable
- jetpack compose - Image from vector
- jetpack compose - Image from bitmap
- jetpack compose - Circular image example