aurelhubert / aurelhubert/ahbottomnavigation

Color not changing on selection

Open
#351 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
3.8k
Forks
672
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at MainActivity.setupbottomnavigation and the setOnTabSelectedListener callback shown in the report; read the listener's return-value contract and compare it with the observed selection behavior. Confirm that the selected item's color changes while the reported position and ripple behavior remain intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile-dev
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.