I’m working on a Jetpack Compose project, and I need to change the background color of a specific area within a screen. Here’s what I have so far:
@Composable fun Bgcolor() { Column( modifier = Modifier .fillMaxSize() .padding(16.dp) ) { Box( modifier = Modifier .fillMaxWidth() .height(200.dp) .background(Color.LightGray) .padding(16.dp) ) { Text(“This is the box”) } } }
I want to move this Box upwards and change its background color. How can I achieve this? I’ve tried using the offset modifier, but I’m not sure if I’m using it correctly. Here is what I tried:
Box( modifier = Modifier .fillMaxWidth() .height(200.dp) .background(Color.LightGray) .padding(16.dp) .offset(y = (-50).dp) ) { Text(“This is the moved box”, color = Color.Black) }
The box does not move up. Any help would be greatly appreciated!
Bihara Malith is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.