Chethan
10/27/2020, 5:29 AM@Preview
@Composable
fun ConfirmationScreen() {
ConstraintLayout(
modifier = Modifier.fillMaxHeight().fillMaxWidth().background(Color.White)
) {
val (topBar, confirmationText, continueButton) = createRefs()
TopAppBarFlat(
topBarTitle = "Screen Title",
topBarColor = Color.White,
topBarLeftIcon = R.drawable.ic_back,
navigation = {
},
modifier = Modifier.constrainAs(topBar) {
top.linkTo(<http://parent.top|parent.top>)
}
)
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxWidth().wrapContentHeight().constrainAs(confirmationText) {
bottom.linkTo(<http://continueButton.top|continueButton.top>)
centerVerticallyTo(parent)
}
) {
Image(
asset = imageResource(id = R.drawable.test),
modifier = Modifier.fillMaxWidth(0.5F)
)
Text(
text = "Screen Title.",
style = TextStyle(
color = Color.Black,
fontSize = 16.sp,
fontWeight = FontWeight.Bold,
textAlign = TextAlign.Center
),
fontSize = 14.sp,
color = Color.Black,
modifier = Modifier.padding(10.dp)
)
Text(
text = "Description....",
style = TextStyle(
color = Color.Black,
fontSize = 14.sp,
fontWeight = FontWeight.Normal,
textAlign = TextAlign.Center
),
fontSize = 14.sp,
color = Color.Black,
modifier = Modifier.padding(start = 50.dp, end = 50.dp)
)
}
Button(
onClick = {
},
modifier = Modifier.fillMaxWidth().padding(10.dp).preferredHeight(40.dp)
.constrainAs(continueButton) {
bottom.linkTo(parent.bottom)
},
backgroundColor = Color.Black
) {
Text(
text = "OK",
style = TextStyle(
color = Color.White,
fontSize = 16.sp,
fontWeight = FontWeight.Bold,
textAlign = TextAlign.Center
)
)
}
}
}
@Composable
fun TopAppBarFlat(
topBarTitle: String,
topBarColor: Color = Color.Black,
topBarLeftIcon: Int = R.drawable.ic_back,
navigation: () -> Unit,
modifier: Modifier = Modifier.fillMaxWidth()
) {
TopAppBar(
elevation = 0.dp,
title = { Text(text = topBarTitle) },
navigationIcon = {
IconButton(onClick = { navigation() }) {
Icon(vectorResource(topBarLeftIcon))
}
},
backgroundColor = topBarColor,
modifier = modifier
)
}
bharat to
10/27/2020, 6:09 AMSurface(Modifier.fillMaxSize()) {
Column(Modifier.padding(10.dp), horizontalAlignment = Alignment.CenterHorizontally) {
Column(Modifier.weight(1f), verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally) {
Box(modifier = Modifier.size(width = 150.dp, height = 150.dp).background(Color.Black))
Text(text = "Screen Title")
Text(text = "Description")
}
Button(onClick = {}, backgroundColor = Color.Black, modifier = Modifier.fillMaxWidth()) {
Text("OK", color = Color.White)
}
}
}
bharat to
10/27/2020, 6:10 AMColumn
Chethan
10/27/2020, 8:56 AMbharat to
10/27/2020, 2:18 PMScaffold
layout https://developer.android.com/codelabs/jetpack-compose-layouts?hl=en#4Chethan
10/28/2020, 5:33 AMbharat to
10/28/2020, 5:41 AMColumn
is enough to put something at top, bottom and center with center as weight 1f
. Can you show how we can't use Column
and Row
for this?Chethan
10/28/2020, 5:43 AMbharat to
10/28/2020, 5:47 AM