The new default Navigation Drawer Activity template in Android Studio
defines its titles and icons in a menu file activity_main_drawer
like thi
I called this method navigationView.setItemIconTintList(null);
in the onCreate
so that i can override the default color of the icon items in navigation drawer like this
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_places);
drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
navigationView.setItemIconTintList(null);
}
Then i changed the color of each icon in navigation drawer using this android:iconTint="@color/metallic_blue"
in activity_places_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="@+id/invite"
android:icon="@drawable/ic_people_orange_24dp"
android:title="@string/menu_invite"
android:fontFamily="@font/roboto_medium" />
</group>
Hope this answer helps.
If you want to set it dynamically you can use:
ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open_drawer, R.string.close_drawer);
actionBarDrawerToggle.getDrawerArrowDrawable().setColor(getResources().getColor(R.color.colorAccent));
You must change the colorAccent in the colors file to which ever color you want :
<color name="colorAccent">whichever color required</color>
This solution worked for me