Reputation: 189
im still learning compose.in this prototype im buiding,my Column containing the card views,in this case 1 dummy card,is overlapping with the appbar. i have tried using scaffold too,same result
here is the Card code:
@Composable
fun DiaryCard(){
val bs = "filler text,strings,anything "+
"jadsjjadj adsnjasjd d saasd" +" sadsad asdasd adsasda" +
"sasdasdas dsa d"
Column {
Spacer(modifier = Modifier.padding(top = 6.dp))
Card(modifier = Modifier
.fillMaxWidth()
.padding(13.dp),
shape = MaterialTheme.shapes.small,
elevation = 5.dp, backgroundColor = Color.White){
Row(modifier = Modifier.padding(bottom = 2.dp)){
Text(text = "29 Sept. 2019", modifier = Modifier
.fillMaxWidth(0.75F)
.padding(start = 1.5.dp),color = Color.Black)
}
Divider()
Spacer(modifier = Modifier.padding(bottom = 3.dp,top = 2.dp))
Column(modifier = Modifier.fillMaxWidth()) {
Text(text = "today was a good day",color = Color.Black)
Spacer(modifier = Modifier.padding(bottom = 3.dp))
Text(text = bs, color = Color.Black)
}
}
}
}
The Appbar:
@Composable
fun topAppbar(){
TopAppBar(backgroundColor = Color.DarkGray) {
}
}
Upvotes: 5
Views: 5857
Reputation: 21
ATTACHING A CODE SNIPPET FROM MY CODE
Scaffold(
topBar = {Top(onNavigationIconClick = {scope.launch {drawerState.open()}})},
bottomBar = { Bottom(navController = navController) },
content= {
Column(modifier = Modifier.padding(it)) { // THE MODIFIER PARAMETER DOES THE MAGIC
Navigation(navController)
}
}
)
Upvotes: 2
Reputation: 187
Since Compose 1.2.0 it's required to use padding parameters, passed into Scaffold content composable. You should apply it to the topmost container/view in the content
@Composable
fun MainScreen() {
Scaffold(topBar = { AppBar() }) {
Surface(modifier = Modifier
.fillMaxSize()
.padding(it)) // Add this to fix it
{
Content()
}
}
}
Upvotes: 7
Reputation: 241
You can use innerPadding,
Scaffold(
topBar = {
TopAppBar(
title = {
Text(
...
)
},
navigationIcon = {
IconButton(onClick = { }) {
Icon(imageVector = Icons.Default.Menu, contentDescription = "Menu Icon" )
}
},
backgroundColor = colorResource(id = R.color.purple_200),
contentColor = Color.White,
elevation = 12.dp
)
},
){
innerPadding ->
Box(modifier = Modifier.padding(innerPadding)){
DiaryCard()
}
}
Upvotes: 14
Reputation: 363439
You can:
Scaffold
with topBar = { topAppbar() }
Column()
to wrap all the content of the CardSomething like:
Scaffold(topBar = { topAppbar() },
) {
DiaryCard()
}
with:
@Composable
fun DiaryCard(){
val bs = "filler text,strings,anything "+
"jadsjjadj adsnjasjd d saasd" +" sadsad asdasd adsasda" +
"sasdasdas dsa d"
Column {
Spacer(modifier = Modifier.padding(top = 6.dp))
Card(
modifier = Modifier
.fillMaxWidth()
//.background(Color.Red)
.padding(13.dp),
shape = MaterialTheme.shapes.small,
elevation = 5.dp, backgroundColor = Color.White
) {
Column() { //It is important to avoid overlap inside the Card
Row(modifier = Modifier.padding(bottom = 2.dp)) {
Text(
text = "29 Sept. 2019", modifier = Modifier
.fillMaxWidth(0.75F)
.padding(start = 1.5.dp), color = Color.Black
)
}
Divider()
Spacer(modifier = Modifier.padding(bottom = 3.dp, top = 2.dp))
Column(modifier = Modifier.fillMaxWidth()) {
Text(text = "today was a good day", color = Color.Black)
Spacer(modifier = Modifier.padding(bottom = 3.dp))
Text(text = bs, color = Color.Black)
}
}
}
}
}
and:
@Composable
fun topAppbar(){
TopAppBar(backgroundColor = Color.DarkGray) {
Text("AppBar")
}
}
Upvotes: 1