aurelhubert / ahbottomnavigation

A library to reproduce the behavior of the Bottom Navigation guidelines from Material Design.
3.84k stars 682 forks source link

Colors aren't working!! #339

Open Misbah-Ahmad opened 6 years ago

Misbah-Ahmad commented 6 years ago

I've tried all constructors of Navigation Items, Setting up the setAccentColor(), setInactiveColor(), But the active and inactive colors of text and icon aren't changing! It gets a default color from nowhere.

my activity code :

`

import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import com.aurelhubert.ahbottomnavigation.AHBottomNavigation; import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity implements AHBottomNavigation.OnTabSelectedListener{

AHBottomNavigation bottomNavigation;

ArrayList<AHBottomNavigationItem> bottomNavigationItems;

AHBottomNavigationItem navigationHomeItem;
AHBottomNavigationItem navigationTrendingItem;
AHBottomNavigationItem navigationReviewItem;
AHBottomNavigationItem navigationSuggestionItem;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    bottomNavigation = findViewById(R.id.bottom_navigation);

    setupBottomNavigationView();

}

private void setupBottomNavigationView(){

    setNavigationItems();

    bottomNavigation.setOnTabSelectedListener(this);

    bottomNavigation.setDefaultBackgroundColor(getResources().getColor(R.color.white));
    bottomNavigation.setAccentColor(R.color.colorPrimary);
    bottomNavigation.setInactiveColor(R.color.black);
    bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW);

    bottomNavigation.setForceTint(true);

    bottomNavigation.setCurrentItem(0);

}

private void setNavigationItems(){

    navigationHomeItem = new AHBottomNavigationItem(getResources().getString(R.string.title_home), R.drawable.ic_home_black_24dp);
    navigationTrendingItem = new AHBottomNavigationItem(getResources().getString(R.string.title_trending), R.drawable.ic_dashboard_black_24dp);
    navigationReviewItem = new AHBottomNavigationItem(getResources().getString(R.string.title_review), R.drawable.ic_notifications_black_24dp);
    navigationSuggestionItem = new AHBottomNavigationItem(getResources().getString(R.string.title_suggestion), R.drawable.ic_home_black_24dp);

/ navigationHomeItem = new AHBottomNavigationItem(R.string.title_home, R.drawable.ic_home_black_24dp, R.color.colorPrimary); navigationTrendingItem = new AHBottomNavigationItem(R.string.title_trending, R.drawable.ic_dashboard_black_24dp, R.color.colorPrimary); navigationReviewItem = new AHBottomNavigationItem(R.string.title_review, R.drawable.ic_notifications_black_24dp, R.color.colorPrimary); navigationSuggestionItem = new AHBottomNavigationItem(R.string.title_suggestion, R.drawable.ic_home_black_24dp, R.color.colorPrimary); /

    bottomNavigationItems = new ArrayList<>();
    bottomNavigationItems.add(navigationHomeItem);
    bottomNavigationItems.add(navigationTrendingItem);
    bottomNavigationItems.add(navigationReviewItem);
    bottomNavigationItems.add(navigationSuggestionItem);

    bottomNavigation.addItems(bottomNavigationItems);

/ bottomNavigation.addItem(navigationHomeItem); bottomNavigation.addItem(navigationTrendingItem); bottomNavigation.addItem(navigationReviewItem); bottomNavigation.addItem(navigationSuggestionItem); /

}

@Override
public boolean onTabSelected(int position, boolean wasSelected) {

    return true;
}

} `

azri92 commented 6 years ago

Could you try ContextCompat.getColor(context, R.color.white)?

primalbet commented 6 years ago

I figured it out, i had the opposite problem of yours. You've put bottomNavigation.setCurrentItem(0); and i've put mNavigationViewPager.setCurrentItem(1);. The first one sets the selected tab in the bottom bar, the second one sets the whole content based on the index. you need to add both of them

RishabhTayal commented 6 years ago

You need to set the color like this:

 bottomNavigation.setAccentColor(getResources().getColor(R.color.colorPrimary));