gpt4 book ai didi

android - 如何更改android studio底部导航栏上选择的图标颜色

转载 作者:行者123 更新时间:2023-12-03 13:28:02 24 4
gpt4 key购买 nike

当我在 android studio 的底部导航栏中选择一个项目时,选择的背景项目等于 values->colors.xml 中的原色。现在我想改变这种与原色不同的颜色。我怎样才能改变它?

    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
Fragment fragment;
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
fragment = new HomeFragment();
loadFragment(fragment);
return true;
case R.id.navigation_addpost:
fragment = new AddFragment();
loadFragment(fragment);
return true;
case R.id.navigation_notifications:
// mTextMessage.setText(R.string.title_notifications);
return true;
case R.id.navigation_profile:
fragment = new ProfileFragment();
loadFragment(fragment);
return true;
}
return false;
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
loadFragment(new HomeFragment());
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
navigation.setItemTextColor(ColorStateList.valueOf(Color.RED));
}

最佳答案

更改 BottomNavigationView 中选定的选项卡图标颜色你应该使用选择器。

创建 bottom_navigation_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/yourSelectedColor" />
<item android:color="@color/defaultColor" />
</selector>

申请 app:itemIconTint="@drawable/bottom_navigation_selector"xml 中的底部导航 View 文件。

关于android - 如何更改android studio底部导航栏上选择的图标颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51579977/

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