2016-04-30 35 views
0

我想實現的底部導航欄,使用AHBottomNavigation庫在:https://github.com/aurelhubert/ahbottomnavigationAHBottomNavigation不變色的Android

我的導航欄的顏色不會改變 - 連鎖反應發生,文字是完美的。我的應用欄保持一種顏色。這裏是代碼:

public void initializeNavigationBar() 
{ 
    menuItemsList = new ArrayList<>(); 
    bottomNavigation = (AHBottomNavigation) findViewById(R.id.bottom_navigation_bar); 
    menuItemsList.add(new AHBottomNavigationItem("Home", R.drawable.home, R.color.colorPrimary)); 
    menuItemsList.add(new AHBottomNavigationItem("View Profile", R.drawable.person_profile, R.color.colorPrimary)); 
    menuItemsList.add(new AHBottomNavigationItem("Map a Route", R.drawable.route, R.color.colorPrimary)); 
    menuItemsList.add(new AHBottomNavigationItem("Start Run", R.drawable.start_run, R.color.colorPrimary)); 
    bottomNavigation.addItems(menuItemsList); 
    bottomNavigation.setAccentColor(Color.parseColor("#FF5722")); 
    bottomNavigation.setInactiveColor(Color.parseColor("#FF5722")); 
    bottomNavigation.setColored(true); 
    bottomNavigation.setForceTint(true); 
    bottomNavigation.setCurrentItem(0); 
    bottomNavigation.setBehaviorTranslationEnabled(false); 
    bottomNavigation.setBackgroundColor(getResources().getColor(R.color.colorPrimary)); 
    bottomNavigation.setOnTabSelectedListener(this); 
} 

@Override 
public void onTabSelected(int position, boolean wasSelected) { 
    switch (position) { 
     case 0: 
      AthleteLandingFragment homeScreen = new AthleteLandingFragment(); 
      FragmentTransaction homeTransaction = mgr.beginTransaction(); 
      homeTransaction.replace(R.id.MainActivityContentArea, homeScreen, 
        "AthleteLandingFragment"); 
      homeTransaction.addToBackStack("AthleteLandingFragment"); 
      toolbarTextView.setText("Athlete Landing Screen"); 
      homeTransaction.commit(); 
      break; 

我不知道我在做什麼錯。我想酒吧是藍色的。我嘗試使用setDefaultBackgroundColor,並沒有工作。

請幫

回答

1

我知道你可能想通了現在,但對其他任何人的東西保存掙扎,問題是R.color.colorPrimary:

menuItemsList.add(new AHBottomNavigationItem("Home", R.drawable.home, R.color.colorPrimary)); 
menuItemsList.add(new AHBottomNavigationItem("View Profile", R.drawable.person_profile, R.color.colorPrimary)); 
menuItemsList.add(new AHBottomNavigationItem("Map a Route", R.drawable.route, R.color.colorPrimary)); 
menuItemsList.add(new AHBottomNavigationItem("Start Run", R.drawable.start_run, R.color.colorPrimary)); 

如果你想整個導航欄要更改爲特定顏色,則必須用該特定顏色替換colorPrimary。通過這種方式,當點擊標籤時,整個導航欄將變爲該顏色。例如。 R.color.RED

2

我也面臨同樣的問題,我已經得到了解決,以及:

bottomNavigation.setColored(假);

請使用上面提到的代碼來解決問題,它對我來說工作得很好。