How to change android jetpack compose bottomAppBar icon tint color?
Asked Answered
I

8

40

BottomNavigationBar() can only take the background and contentColor but there is no option for tint color.

Infuriate answered 15/2, 2021 at 16:20 Comment(0)
L
58

If you want to change the tint color of the image then you can use the colorFilter property of the Image

Image(
    painter = painterResource(R.drawable.ic_arrow_details), 
    contentDescription = "", 
    colorFilter = ColorFilter.tint(Color.Black)
)
Liter answered 15/7, 2021 at 6:50 Comment(0)
M
46

If you want to remove completly the tint color and you would like to use icon's colors then try with: tint = Color.Unspecified

For example:

Icon(
    modifier = Modifier.size(34.dp),
    imageVector = ImageVector.vectorResource(id = R.drawable.ic_your_icon),
    contentDescription = "Some icon",
    tint = Color.Unspecified
)
Manaus answered 14/11, 2021 at 22:1 Comment(0)
C
19

In case you didn't want to change content color, and wanted to have an individual color for specific Icon, there is a tint property. Like:

Icon(
 Icons.Filled.PushPin, "",
 tint = MaterialTheme.colors.secondary
)

But as others said, you can use unselectedContentColor and selectedContentColor in your NavigationItem.

Chaunceychaunt answered 1/9, 2021 at 7:47 Comment(0)
W
9

For BottomNavigation, you need to provide BottomNavigationItem to construct it, while constructing BottomNavigationItem, you can use Icon with tint as resource like below

BottomNavigation() {
    BottomNavigationItem(icon = { 
           Icon(asset = vectorResource(id = R.drawable.homeBottomNav), tint = Color.Blue) //this is tint
       }, selected = true, onClick = {})
}
Woman answered 15/2, 2021 at 16:50 Comment(0)
P
3

With the 1.0.0 (tested with 1.0.0-beta06) in the BottomNavigationItem you can define the attributes:

  • selectedContentColor
  • unselectedContentColor

Something like:

    BottomNavigation(backgroundColor = Color.White) {
            BottomNavigationItem(
                selectedContentColor = Color.Red,
                unselectedContentColor = Color.Gray,
                icon = {
                    Icon(Icons.Filled.Add, "contentDescription")
                },
                selected = true,
                onClick = {})
            BottomNavigationItem(
                selectedContentColor = Color.Red,
                unselectedContentColor = Color.Gray,
                icon = {
                    Icon(Icons.Filled.Search, "contentDescription")
                },
                selected = false,
                onClick = {})
    }

enter image description here

Also since the default selectedContentColor is based on the LocalContentColor.current you can also use something like:

    BottomNavigation(backgroundColor = Color.White) {
        CompositionLocalProvider(LocalContentColor provides Color.Red) {
            BottomNavigationItem(
                icon = {
                    Icon(Icons.Filled.Add, "contentDescription")
                },
                selected = true,
                onClick = {})
            BottomNavigationItem(
                icon = {
                    Icon(Icons.Filled.Search, "contentDescription")
                },
                selected = false,
                onClick = {})
        }
    }

enter image description here

Pasley answered 7/4, 2021 at 7:17 Comment(1)
you should change selected dynamically!Porscheporsena
O
2

You can use unselectedContentColor and selectedContentColor.

BottomNavigationItem(
   unselectedContentColor = Color.Black,
   selectedContentColor = Color.Red,
   icon = {
       Icon(
           painter = painterResource(id = screen.iconResourceId),
           contentDescription = null)
           },
    selected = currentRoute == screen.route,
    onClick = { }
)
Odessaodetta answered 1/4, 2021 at 11:38 Comment(0)
P
0

selectedContentColor changes color of Text and Icon, but not Image() Composable. So if you want to keep color of multicolor-icon when selected, one should use Image(). Also you want to make it grayscale when unselected, you can use colorFilter.

Plus if you don't want to change color of Text/Icon, then you can use Color.Unspecified.

Pippin answered 28/8, 2021 at 15:30 Comment(0)
S
0

This is for rating menu, product or something like that. I hope you benefit from it.

Row(modifier = Modifier.fillMaxWidth()) {
                repeat(5) { index ->
                    Icon(
                        imageVector = Icons.Default.Star,
                        contentDescription = "Star$index",
                        tint = if (index < rating) Color.Yellow else Color.Gray,
                        modifier = Modifier.size(13.dp)
                    )
                }
            }
Succinct answered 26/12, 2023 at 19:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.