Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

      }
     }
like image 563
Tygris Avatar asked Aug 24 '26 07:08

Tygris


2 Answers

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()
    }
}
like image 106
Monica Patel Avatar answered Aug 25 '26 23:08

Monica Patel


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()
        }
    }
}
like image 40
Akshay Ashok Avatar answered Aug 25 '26 21:08

Akshay Ashok



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!