AHBottomNavigation Not Changing Color Android



我正在尝试使用AHBottomNavigation库实现底部导航栏,位于:https://github.com/aurelhubert/ahbottomnavigation

我的导航栏的颜色没有改变——波纹效果发生了,文本是完美的。我的应用程序栏保持不变。这是代码:

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,但没有成功。

请帮助

我也面临同样的问题,我也得到了解决方案:

bottomNavigation.setColored(false);

请使用上面提到的代码来解决这个问题,它对我来说很好。

我知道你现在可能已经想通了,但对于其他在保存问题上挣扎的人来说,问题是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

嘿,你能这样改变吗:

    navigationHome = new AHBottomNavigationItem(getResources().getString(R.string.home), R.drawable.ic_home);
    navigationWishlist = new AHBottomNavigationItem(getResources().getString(R.string.wishlist), R.drawable.ic_wishlist);
    navigationAccount = new AHBottomNavigationItem(getResources().getString(R.string.account), R.drawable.ic_account);
    bottomNavigation.addItem(navigationHome);
    bottomNavigation.addItem(navigationWishlist);
    bottomNavigation.addItem(navigationAccount);
    bottomNavigation.setAccentColor(ContextCompat.getColor(this, R.color.colorPrimary));

该代码适用于我

这段代码对我有用:

bottomNavigation.setColored(true);

我的项目颜色随着每次点击而变化。

最新更新