How to change Toolbar Navigation and Overflow Menu icons (appcompat v7)?

后端 未结 11 1788
离开以前
离开以前 2020-11-29 19:11

I am having a hard time with v7 Toolbar. What was once a simple task for ActionBar, now seems overly complex. No matter what style I set, I cannot change either

11条回答
  •  一生所求
    2020-11-29 20:06

    if you want to change your icons to a Vector , create a new one. and then in your Activity.java :

    Toolbar toolbar = findViewById(R.id.your_toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    toolbar.setNavigationIcon(R.drawable.your_icon);
    mToolbar.setOverflowIcon(ContextCompat.getDrawable(this, R.drawable.your_icon2));
    

    To change Vector icon Color, go to your Vector XML file.. in this case it will be your_icon.xml, it will look like this :

    
    
    

    Note that we used these attributes to set the Vector's color :

    android:fillColor="@color/Your_Color"
    

    Edit : You can't use a color from your colors.XML or somewhere else , the color must be decalred directly in the Vector's XML file.. so it will look like this :

    android:fillColor="#FFF"
    

提交回复
热议问题