2

I using this library for using BottomBar in my app and I can't set background color for this BottomBar.

My code:

 mBottomBar = BottomBar.attach(parent.findViewById(R.id.content), savedInstanceState);
    mBottomBar.setItemsFromMenu(R.menu.bottombar_menu, new OnMenuTabClickListener() {
        @Override
        public void onMenuTabSelected(@IdRes int menuItemId) {

        }

        @Override
        public void onMenuTabReSelected(@IdRes int menuItemId) {

        }
    });

    mBottomBar.mapColorForTab(0, ContextCompat.getColor(getActivity(), R.color.colorAccent));
    mBottomBar.mapColorForTab(1, ContextCompat.getColor(getActivity(), R.color.colorAccent));

My BottomBar background color is white - I want set BootomBar like: enter image description here

UPD 1 I tried this code:

mBottomBar.setBackgroundColor(getResources().getColor(R.color.colorAccent));

But this change background on my content (Look to Content for nearby in screenshot), doesn't in BottomBar

476rick
  • 2,764
  • 4
  • 29
  • 49
Artem
  • 4,569
  • 12
  • 44
  • 86

2 Answers2

3

Try with this. It works for me

mBottomBar.getBar().setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorAccent));
Masum
  • 4,879
  • 2
  • 23
  • 28
  • @dwinnbrown Great. I think It shows deprecated in this line getResources().getColor(R.color.colorAccent). I have updated the code. Now I believe it will resolve your deprecated. – Masum Jul 13 '16 at 11:00
  • I believe that yes that will work however it gives me an error `cannot get method 'getActivity()'` - could be because I didn't update the gradle file? – dwinnbrown Jul 13 '16 at 11:02
  • If your BottomBar in fragment, use getActivity() else in Activity then use YourActivity.this – Masum Jul 13 '16 at 11:03
  • I am using fragments but am trying to set this in the main activity file. – dwinnbrown Jul 13 '16 at 11:06
  • You don't know how to solve this: http://stackoverflow.com/questions/38349897/how-to-set-inactive-tab-colour-for-bottombar by any chance? – dwinnbrown Jul 13 '16 at 11:07
  • I recommend using it on your activity – Masum Jul 13 '16 at 11:07
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/117200/discussion-between-dwinnbrown-and-masum). – dwinnbrown Jul 13 '16 at 11:08
1

The accepted answer didn't work for me, I tried something else. When you change the background for each you have it does work. I added this line for every tab I have:

bottomBar.getTabAtPosition(0).setBackgroundColor(backgroundColorInt);
476rick
  • 2,764
  • 4
  • 29
  • 49