【发布时间】:2018-02-02 13:32:19
【问题描述】:
这里闪烁: 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>
【问题讨论】:
-
TextView的闪烁通常意味着您在不断地重绘它。您可以将您正在设置文本的Activity中的代码添加到TextView吗? -
你来了,造型很抱歉,我是新来的。
-
我没有手动设置文本,它会自动更改,来自 menu.xml
-
现在我看到了你的 gif,我不知道你说的眨眼是什么意思。它看起来像一个正常的涟漪效应。
-
是的,你是对的,它的连锁反应,我只是检查一下。好的,谢谢你的帮助))
标签: android xml selector drawable android-bottom-nav-view