Does anyone know how to change the background colour of a tabbed view bottom bar?
I have set the accent colour which changed the colour of my icons when I select each tab bar item.
I have tried setting the background to a colour but it doesn't change the back, and tried setting background to an image just to be sure but that also doesn't do anything.
Wondering if I need to specifically access the bottom bar somehow and then set a property on that?
If you ever tried to change the colors of TabItems in your TabView , you might find that this is only possible via the TabViews accentColor modifier — which sets the color for all TabItems . If you want to have different colors for each item, set the accent color by using .
To change tab bar background color in Flutter, first, create a getter to return the TabBar widget and then wrap the TabBar widget inside the PreferredSize -> Material widget. Inside the Material add the color property and set the color of your choice.
barTintColor
and isTranslucent
For some reason I wasn't getting the full color of my named color when I used just barTintColor
or even backgroundColor
. I had to include isTranslucent
too.
Here is my named color:
barTintColor
(As you can see, it is slightly faded)
backgroundColor
(This darkens the bar a little bit)
barTintColor
& isTranslucent
to FalseThis combination is what did it for me:
UITabBar.appearance().isTranslucent = false
UITabBar.appearance().barTintColor = UIColor(named: "Secondary")
Here is a solution. You can change appearance
of the UITabBar and change the TabBar.
struct TabView: View {
init() {
UITabBar.appearance().backgroundColor = UIColor.blue
}
var body: some View {
return TabbedView {
Text("This is tab 1").tag(0).tabItemLabel(Text("tab1"))
Text("This is tab 2").tag(1).tabItemLabel(Text("tab2"))
Text("This is tab 3").tag(2).tabItemLabel(Text("tab3"))
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With