Search code examples
kotlinandroid-jetpack-composebackground-color

Cannot add Background color on Kotlin Jetpack Compose


I want to add a background color on my Floating Action Button but I cannot seem to add it. On older Yotuube videos adding a backgroundColor would make it possible but it seems that it is not possible to do it now. Any help?

@Composable
fun HomeView(){
    val context = LocalContext.current
    Scaffold(

        topBar = {AppBarView(title = "WishList",{
            Toast.makeText(context,"Button Clicked:",Toast.LENGTH_LONG).show()

        })},
        floatingActionButton = {
            FloatingActionButton(
                modifier = Modifier.padding(all = 20.dp),
                contentColor = Color.White,
                //I want to add a Background color here
                onClick = { //TODO Add Navigation to edit screen}) {
                
            }
        }
    ) {
        LazyColumn(modifier = Modifier
            .fillMaxSize()
            .padding(it)){

        }
    }
}```

Solution

  • You can use containerColor for it. In the docs it says

    the color used for the background of this FAB. Use Color.Transparent to have no color.

    If you don't set it, the contentColor is used by default.