我在我的应用程序中集成了底部栏导航栏。但是当我滑动时,标签的颜色不会改变。这很奇怪,因为我有选择器文件。有什么想法可以解决这个问题吗?
活动.java
BottomNavigationView bottomNavigationView = (BottomNavigationView)
findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.bb_menu_arac:
fragment = new AraclarimFragment();
break;
case R.id.bb_menu_yaklasan:
fragment = new YaklasanlarFragment();
break;
case R.id.bb_menu_yakin:
fragment = new Yakinimdakiler();
break;
}
final FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.main_container, fragment).commit();
return true;
}
});
选择器.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/beyaz" android:state_enabled="true" />
<item android:color="@color/colorPrimaryDark" android:state_enabled="false" />
</selector>
活动.xml
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@color/beyaz"
app:itemTextColor="@color/beyaz"
app:menu="@menu/bottombar_menu" />