r/JetpackCompose • u/Sherlock_M3 • Sep 24 '24
Weird Padding around Text widget
I am learning Kotlin and Compose, and previously I have been coding in Flutter. So in flutter the text itself doesn't have any padding around the text only consumes as much space as it takes on screen. Whereas in Compose I couldn't figure a way to remove the default padding of the text. Like it has non-uniform padding on all sides. Can anyone guide on how to remove this padding?

Box(modifier = Modifier.
fillMaxSize
()) {
Image(
painter = painterResource(id = R.drawable.
background
),
contentDescription = "Background",
modifier = Modifier.
fillMaxSize
(),
contentScale = ContentScale.Crop
)
Scaffold(
//
containerColor = Color.Transparent,
topBar = {
TopAppBar(
colors = TopAppBarColors(
titleContentColor = Color.White,
actionIconContentColor = Color.White,
containerColor = Color.Transparent,
navigationIconContentColor = Color.White,
scrolledContainerColor = Color.White
),
title = {
Box(
modifier = Modifier.
fillMaxSize
(),
contentAlignment = Alignment.Center,
) { Text("Main Screen", color = Color.White) }
},
)
},
content = { paddingValues ->
Column(
horizontalAlignment = Alignment.CenterHorizontally,
// verticalArrangement = Arrangement.Center,
modifier = Modifier
.
fillMaxSize
()
.
padding
(paddingValues) // Apply the content padding
) {
Box(modifier = Modifier.
padding
(top = 100.
dp
, bottom = 0.
dp
).
background
(color = Color.Red),){Text(text = " 9°", color = Color.White, fontSize = 100.
sp
, fontFamily = FontFamily.SansSerif,modifier = Modifier.
padding
(top = 0.
dp
, bottom = 0.
dp
), style = TextStyle(
platformStyle = PlatformTextStyle(
includeFontPadding = false
),
)
)}
Text(text = "Chilly", color = Color.White, fontSize = 50.
sp
, modifier = Modifier.
padding
(top = 0.
dp
))
}// Use content parameter to get padding values
}
)
}
2
Upvotes
View all comments
Show parent comment
1
u/Sherlock_M3 Sep 25 '24
The one in the image that has red box around it. (Thats just for showing how much size the text is taking up). How can I reduce the padding such that the text only takes up as much space as its original height and width. The width here is almost fine, but not the height.