aurelhubert / ahbottomnavigation

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

Color not changing on selection #351

Open Miteshmakwana73 opened 6 years ago

Miteshmakwana73 commented 6 years ago

This is my code, my problem is after applying setOnTabSelectedListener it stops working to change item color. if I remove setOnTabSelectedListener it's working great

position, ripple effect working properly what should I do, please suggest me

 public class MainActivity extends AppCompatActivity {
 private AHBottomNavigation bottomNavigation;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    boolean enabledTranslucentNavigation = getSharedPreferences("shared", Context.MODE_PRIVATE)
            .getBoolean("translucentNavigation", false);
    setTheme(enabledTranslucentNavigation ? R.style.AppTheme_TranslucentNavigation : R.style.AppTheme);
    bottomNavigation = findViewById(R.id.bottom_navigation);
    setupbottomnavigation();

}

private void setupbottomnavigation() {
    AHBottomNavigationItem item1 = new AHBottomNavigationItem(R.string.Home, R.drawable.ic_home_black_24dp, R.color.color_tab_1);
    AHBottomNavigationItem item2 = new AHBottomNavigationItem(R.string.Search, R.drawable.ic_search_black_24dp, R.color.color_tab_2);
    AHBottomNavigationItem item3 = new AHBottomNavigationItem(R.string.Category, R.drawable.ic_apps_black_24dp, R.color.color_tab_3);
    AHBottomNavigationItem item4 = new AHBottomNavigationItem(R.string.Favourite, R.drawable.ic_favorite_black_24dp, R.color.color_tab_4);

    bottomNavigation.addItem(item1);
    bottomNavigation.addItem(item2);
    bottomNavigation.addItem(item3);
    bottomNavigation.addItem(item4);

    bottomNavigation.setDefaultBackgroundColor(Color.parseColor("#FEFEFE"));

    // Change colors

    bottomNavigation.setForceTint(true);
    bottomNavigation.setColored(false);

    bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_HIDE);

    bottomNavigation.setOnNavigationPositionListener(new AHBottomNavigation.OnNavigationPositionListener() {
        @Override
        public void onPositionChange(int y) {
            showToast(String.valueOf(y));
        }
    });

    bottomNavigation.setOnTabSelectedListener(new AHBottomNavigation.OnTabSelectedListener() {
        @Override
        public boolean onTabSelected(int position, boolean wasSelected) {
            showToast(String.valueOf(position));
            return false;
        }
    });
}

private void showToast(String msg) {
    Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}
}`

Any help would be highly appreciated.

dario30186 commented 5 years ago

I am having the same issue, did you find a solution ?

Miteshmakwana73 commented 5 years ago

No, i use this library

bink-develop commented 5 years ago

you should return true in "onTabSelected" . bottomNavigation.setOnTabSelectedListener(new AHBottomNavigation.OnTabSelectedListener() { @Override public boolean onTabSelected(int position, boolean wasSelected) { showToast(String.valueOf(position)); return true; } });