MainActivity.kt
package com.cfsuman.jetpackcompose
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.*
import androidx.compose.ui.graphics.drawscope.Stroke
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(){
Canvas(
modifier = Modifier
.fillMaxSize()
.background(Color(0xFFFFDAE9))
)
{
drawRect(
color = Color(0xFF9D2933),
size = Size(
width = 300.dp.toPx(),
height = 150.dp.toPx()
),
topLeft = Offset(
x = 50.dp.toPx(),
y = 50.dp.toPx()
)
)
drawRect(
color = Color(0xFF26619C),
size = Size(
width = 300.dp.toPx(),
height = 125.dp.toPx()
),
topLeft = Offset(
x = 50.dp.toPx(),
y = 250.dp.toPx()
),
style = Stroke(
width = 8.dp.toPx(),
miter = 15.dp.toPx(),
cap = StrokeCap.Round,
pathEffect = PathEffect.cornerPathEffect(8.dp.toPx())
)
)
}
}
@Preview
@Composable
fun ComposablePreview(){
//MainContent()
}
}
- jetpack compose - How to use Text
- jetpack compose - ClickableText example
- jetpack compose - How to use Button
- jetpack compose - Password TextField example
- jetpack compose - Handle changes in a TextField
- jetpack compose - Radio group example
- jetpack compose - How to use Floating Action Button
- jetpack compose - How to use IconToggleButton
- jetpack compose - How to use Column layout
- jetpack compose - How to use Row layout
- jetpack compose - Animate content size
- jetpack compose - Draw circle on canvas
- jetpack compose - Draw rounded rectangle on canvas
- jetpack compose - Draw oval on canvas
- jetpack compose - Rotate canvas