https://kotlinlang.org logo
#compose
Title
# compose
a

Alejandro Rios

07/08/2020, 1:55 AM
this is my code
Copy code
@Composable
@Preview(showBackground = true)
fun DefaultRecipeCard() {
    Scaffold(topAppBar = {
        TopAppBar(
            title = {
                Text(text = "ComposablecookBok")
            }
        )
    }, bodyContent = {
        RecipeList(defaultRecipes)
    }, bottomAppBar = BottomAppBar {
        Text(
            text = "Jetpack Compose",
            modifier = Modifier.padding(16.dp)
        )
    }
    )
}
n

nglauber

07/08/2020, 4:15 AM
This worked for me 😉
Copy code
bottomBar = {
    BottomAppBar(content = {
        BottomNavigationItem(
            icon = {
                Icon(Icons.Default.Person)
            },
            selected = bottomBarSelectedIndex == 0,
            onSelected = { bottomBarSelectedIndex = 0 },
            activeColor = Color.Magenta,
            inactiveColor = Color.LightGray
        )
        BottomNavigationItem(
            icon = {
                Icon(Icons.Default.Favorite)
            },
            selected = bottomBarSelectedIndex == 1,
            onSelected = { bottomBarSelectedIndex = 1 },
            activeColor = Color.Magenta,
            inactiveColor = Color.LightGray
        )
        BottomNavigationItem(
            icon = {
                Icon(Icons.Default.Settings)
            },
            selected = bottomBarSelectedIndex == 2,
            onSelected = { bottomBarSelectedIndex = 2 },
            activeColor = Color.Magenta,
            inactiveColor = Color.LightGray
        )
    })
},
and this is the
bottomBarSelectedStateIndex
Copy code
var bottomBarSelectedIndex by state { 0 }
👏🏼 1
t

Timo Drick

07/08/2020, 8:32 AM
In dev14 it is "bottomBar =" and not "bottomAppBar ="
👍🏼 1
m

matvei

07/08/2020, 8:59 AM
You need to call lambda that will will invoke BottomAppBar @Composable as a slot.
Copy code
bottomAppBar = BottomAppBar {
        Text(
            text = "Jetpack Compose",
            modifier = Modifier.padding(16.dp)
        )
    }
should become
Copy code
bottomAppBar = { 
    BottomAppBar {
        Text(
            text = "Jetpack Compose",
            modifier = Modifier.padding(16.dp)
        )
    }
}
Haha, just saw that Adam answered below, nvm %)
a

Alejandro Rios

07/12/2020, 5:51 PM
Thanks @nglauber, @Timo Drick, @matvei for the comments
👍 1
2 Views