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.inset
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(0xFFDEB887))
)
{
inset(
horizontal = 50.dp.toPx(),
vertical = 70.dp.toPx()
){
drawRect(color = Color(0xFFEDEAE0))
drawRect(
color = Color(0xFF915C83),
topLeft = Offset(
x = 20.dp.toPx(),
y = 20.dp.toPx()
),
size = Size(
width = size.width - 40.dp.toPx(),
height = 50.dp.toPx()
)
)
drawRect(
color = Color(0xFFFF9966),
topLeft = Offset(
x = 20.dp.toPx(),
y = size.height - 70.dp.toPx()
),
size = Size(
width = size.width - 40.dp.toPx(),
height = 50.dp.toPx()
)
)
}
}
}
@Preview
@Composable
fun ComposablePreview(){
//MainContent()
}
}
- jetpack compose - How to use IconToggleButton
- jetpack compose - LinearProgressIndicator example
- jetpack compose - CircularProgressIndicator example
- jetpack compose - Navigation drawer example
- jetpack compose - How to use Scaffold
- jetpack compose - Cut corner shape example
- jetpack compose - Image from drawable
- jetpack compose - Image clickable
- jetpack compose - Image border
- jetpack compose - Image shape
- jetpack compose - Image tint
- jetpack compose - Canvas withTransform
- jetpack compose - Draw arc on canvas
- jetpack compose - Draw image on canvas
- jetpack compose - Draw text on canvas