这里闪烁: http: //gph.is/2GH9P0b
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
style="@style/BottomNavigation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
样式.xml
<style name="BottomNavigation">
<item name="android:background">@color/colorPrimary</item>
<item name="itemIconTint">@drawable/nav_bottom_selector</item>
<item name="itemTextColor">@drawable/nav_bottom_text_selector</item>
</style>
选择器nav_bottom_text_selector
和nav_bottom_selector
具有相同的代码。
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/white" android:state_checked="true"/>
<item android:color="#6e6e6e" />
MainActivity.class 这是选项卡更改侦听器。但我认为问题不在这里,因为即使我评论这部分,它仍然在闪烁。
navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected (@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_exercises:
// even not replace tabs, just hide and show
fragmentManager.beginTransaction().show(exerciseFragment).hide(workoutFragment).hide(profileFragment).commit();
SharedPrefsHelper.getInstance().setLastTab(getApplicationContext(), ConsKeys.BOTTOM_TAB_EXERCISE);
break;
case R.id.navigation_workouts:
fragmentManager.beginTransaction().hide(exerciseFragment).show(workoutFragment).hide(profileFragment).commit();
SharedPrefsHelper.getInstance().setLastTab(getApplicationContext(), ConsKeys.BOTTOM_TAB_WORKOUTS);
break;
case R.id.navigation_profile:
fragmentManager.beginTransaction().hide(exerciseFragment).hide(workoutFragment).show(profileFragment).commit();
//Saving last tab
SharedPrefsHelper.getInstance().setLastTab(getApplicationContext(), ConsKeys.BOTTOM_TAB_PROFILE);
break;
}
return true;
}
});
底部导航视图的导航 menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/navigation_exercises"
android:icon="@drawable/ic_home_black_24dp"
android:title="@string/title_exercises" />
<item
android:id="@+id/navigation_workouts"
android:icon="@drawable/ic_dashboard_black_24dp"
android:title="@string/title_workouts" />
<item
android:id="@+id/navigation_profile"
android:icon="@drawable/ic_notifications_black_24dp"
android:title="@string/title_profile" />
</menu>