When I select an item in bottom navigation bar in android studio, background item selected is equal to primarycolor in values->colors.xml . and now I want to change this color which is not to same the primarycolor. how do i can to change it?
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));
}
If you are using the BottomNavigationView, the solution could be easy. You just need to create a selector as a ColorStateList, then assign the selector to the "itemIconTint" attribute of the BottomNavigationView.
Steps for Creating Bottom Navigation Bar. Step 1: Create a new Android Studio project. To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Kotlin as the programming language. Step 2: Adding the dependency to the build.gradle(:app) file
Hi, is it possible to change the icons and color of Android bottom navigation bar on phone or tablet ? If yes, how can I do it ? Settings > Display > Navigation Bar. You can also change the style of navigation bar by choosing other theme. Advanced customization of navigation bar is possible with some apps, that you need to download.
To change the selected tab icon color in BottomNavigationView you should use the Selector. Create bottom_navigation_selector.xml Apply app:itemIconTint="@drawable/bottom_navigation_selector" to your BottomNavigationView in xml file.
React Native Navigation Bar Color Change is a React Native library for change color of navigation/Bottom bar on Android. That's is all! Open up android/app/src/main/java/ [...]/MainApplication.java Add import com.thebylito.navigationbarcolor.NavigationBarColorPackage; to the imports at the top of the file
To change the selected tab icon color in BottomNavigationView
you should use the Selector.
Create 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>
Apply app:itemIconTint="@drawable/bottom_navigation_selector"
to your BottomNavigationView in xml
file.
Despite reading all the answers I was confused about whole process, so I am going to explain step by step how I resolved this issue so beginners can understand it properly
Let's assume you created bottom navigation activity with name MainActivity
so now
create bottom_navigation_selector.xml
in your drawable
folder using this code
<?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>
then go to the activity_main.xml
layout and add this line in BottomNavigationView
app:itemIconTint="@drawable/bottom_navigation_selector"
If you also want to change text color accordingly then you need to add this line aswell
app:itemTextColor="@drawable/bottom_navigation_selector"
To show the real color of items use this
java
bottom_navigation.setItemIconTintList(null);
kotlin
bottom_navigation.itemIconTintList = null
and if you want to change the calor just replace the null with
Color.parseColor("#ffffff")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With