Bottombar: How do I set the background color?

Created on 4 May 2016  Â·  9Comments  Â·  Source: roughike/BottomBar

I'd like to have my BottomBar use a custom color as the background for tabs, with non-selected tabs using another custom color for text/icon (essentially a darker version of said custom color), and the selected tab using white for text/color. So the same background color at all times, across all tabs. Sounds simple, but how can I accomplish this?

I have so far found useDarkMode which causes the bottom bar to be dark grey with white icons. If not using dark mode, the bottom bar is instead light grey with dark icons.

If setting setMaxFixedTabs(n-1), and NOT mapping any colors to tabs, my bottom bar gets the primaryColor from the theme as the background, with tabs in white/grey. This seems fairly undocumented, and why is there no way of having the BottomBar use R.attr.primaryColor without fixed tabs mode - why just light or dark..?

If I _do_ use mapColorForTab, I can have my custom color as the background, but this _only_ works if setMaxFixedTabs is used, which I don't particularly like due to the offset/resize effects (if having three tabs, I think it looks strange when the middle tab is not center-fixed). Also, I am not sure from where the unselected tabs get their color (it looks like white with 0.5 alpha or something).

Is there some combination of attributes I can use to achieve what I need? Why is there no simple setTabBackground and setInactiveTabColor?

I also noted that if using View.setBackgroundColor on the BottomBar, the background of my activity is instead changed; I guess this is because BottomBar is essentially a full-screen FrameLayout?

Most helpful comment

I found this ugly workaround for setting the background color:

mBottomBar.findViewById(R.id.bb_bottom_bar_background_view).setBackgroundColor(myColor);

But regarding unselected tab colors for text/icon, it seems mInActiveColor is hard-coded to mInActiveColor = ContextCompat.getColor(getContext(), R.color.bb_inActiveBottomBarItemColor);

I suggest adding setTabBackgroundColor(int) and setInactiveTabColor(int), what do you think?

All 9 comments

I found this ugly workaround for setting the background color:

mBottomBar.findViewById(R.id.bb_bottom_bar_background_view).setBackgroundColor(myColor);

But regarding unselected tab colors for text/icon, it seems mInActiveColor is hard-coded to mInActiveColor = ContextCompat.getColor(getContext(), R.color.bb_inActiveBottomBarItemColor);

I suggest adding setTabBackgroundColor(int) and setInactiveTabColor(int), what do you think?

You can override the styles.xml in your app and give the background colors there.

Can I? AFAIK you are not referencing styleable attributes but hard coded color ids? Would you mind adding an example to the readme?

Ok so I understand how to change the inactive tab by declaring my own color with the name bb_inActiveBottomBarItemColor. Will this work also on pre-M devices though?

And regarding the background color I still see no way of simply overriding a color. As far as I can see, if NOT using the dark theme and NOT using fixed tabs, no call will be made to set the backgroundColor of mBackgroundView at all. It will get #ffffff hard-coded from the layout. I still see no way of changing it short of manually finding the R.id.bb_bottom_bar_background_view view?

Also wondering about this issue, any news here?

I have the same problem with this!

Ugh. Was it really this bad before?

With the new version, you can just go like android:background like it should've been all along.

Ok guys, i can't setBackground programmatically. I don't know why.

This works :
<com.roughike.bottombar.BottomBar android:id="@+id/bottomBar" android:layout_width="match_parent" android:layout_height="60dp" android:background="@color/colorAccent" android:layout_alignParentBottom="true" app:bb_tabXmlResource="@xml/bottombar_tabs" />

But this not :
BottomBar bottomBar = (BottomBar) findViewById(R.id.bottomBar); bottomBar.setBackground(ContextCompat.getDrawable(this,R.color.colorAccent));

Can you help me for this ?

Shouldn't you be using getColor() as opposed to getDrawable()?

I'm thinking the system fails to find a _drawable_ with the id of your _color_, and it ends up as a no-op?

Den 3 nov 2016 6:38 em skrev Etienne Théodore [email protected]:

Ok guys, i can't setBackground programmatically. I don't know why.

This works :
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@color/colorAccent"
android:layout_alignParentBottom="true"
app:bb_tabXmlResource="@xml/bottombar_tabs" />

But this not :
BottomBar bottomBar = (BottomBar) findViewById(R.id.bottomBar);
bottomBar.setBackground(ContextCompat.getDrawable(this,R.color.colorAccent));

Can you help me for this ?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHubhttps://github.com/roughike/BottomBar/issues/205#issuecomment-258217376, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJKcQhLoRfWGr3WagEd7e_gRIadi5o58ks5q6hwCgaJpZM4IXJsZ.

Was this page helpful?
0 / 5 - 0 ratings