AHBottomNavigation不改变颜色Android

时间:2016-04-30 20:47:35

标签: android android-layout

我正在尝试使用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,但没有用。

请帮忙

4 个答案:

答案 0 :(得分:3)

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

bottomNavigation.setColored(假);

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

答案 1 :(得分:2)

我知道你现在可能已经知道了,但对于其他任何挣扎着保存的人来说,问题是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 :(得分:0)

嘿,你可以这样改变自己吗:

    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));

此代码对我有用

答案 3 :(得分:-1)

此代码对我有用:

bottomNavigation.setColored(true);

我的商品的颜色随着每次点击而改变。