Change color of Navigation Drawer Icon in Android Studio default template

前端 未结 9 983
北恋
北恋 2020-12-13 05:52

The new default Navigation Drawer Activity template in Android Studio

defines its titles and icons in a menu file activity_main_drawer like thi

相关标签:
9条回答
  • 2020-12-13 06:27

    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.

    0 讨论(0)
  • 2020-12-13 06:28

    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));
    
    0 讨论(0)
  • 2020-12-13 06:29

    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

    0 讨论(0)
提交回复
热议问题