gpt4 book ai didi

android - BottomNavigationBar-更改选项卡图标颜色

转载 作者:可可西里 更新时间:2023-11-01 19:11:24 25 4
gpt4 key购买 nike

我在我的应用程序中集成了底部栏导航栏。但是当我滑动时,选项卡的颜色不会改变。这很奇怪,因为我有选择器文件。有解决这个问题的想法吗?

Activity.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>

activity.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" />

最佳答案

更改为 app:itemIconTint="@drawable/selector"

同时将您的 selector.xml 更改为:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@color/beyaz" />
<item android:color="@color/colorPrimaryDark" />
</selector>

关于android - BottomNavigationBar-更改选项卡图标颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42346899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com