【发布时间】:2020-04-26 16:12:39
【问题描述】:
底部导航的所选项目的颜色没有改变,尽管我提供了控制颜色变化的可绘制文件。我已经尝试了很多次,但我在代码中找不到错误。
请帮忙!
这是底部导航
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="@color/bottomBackground"
app:itemTextColor="@drawable/icon_color"
app:itemIconTint="@drawable/icon_color"
app:labelVisibilityMode="labeled"
app:menu="@menu/bottom_navigation_menu"/>
这是图标颜色
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorAccent" android:state_checked="true"/>
<item android:color="@color/grey" android:state_checked="false"/>
</selector>
编辑:
当我删除这段代码时,它工作正常
BottomNavigationView navigation = findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
int id = menuItem.getItemId();
if(id == R.id.navigation_library) {
loadFragment(new LibraryFragment());
}
else if (id == R.id.navigation_for_you) {
loadFragment(new ForYouFragment());
}
return false;
}
});
为什么这段代码会干扰我的功能。
【问题讨论】:
-
在颜色文件夹中移动 icon_color 选择器。
-
@GabrieleMariotti 我找不到颜色文件夹。你能建议在哪里看吗
-
只需创建
res/color文件夹并将文件放入其中。参考app:itemTextColor="@color/icon_color" -
我试过了,但没用
-
感谢您的支持@GabrieleMariotti 我终于解决了。
标签: android android-layout android-xml bottomnavigationview material-components