Compose Appbar overlaps activity content

see image,Card overlapping the appbar

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) {

      }
     }

Answer

You can:

  • Add a Scaffold with topBar = { topAppbar() }
  • Add a Column() to wrap all the content of the Card

Something 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")
    }
}

enter image description here