Development issue/problem:

I am having problems with the v7 toolbar. What was once a simple task for the ActionBar now seems too complicated. No matter what style I choose, I cannot change the navigation icon (which opens the box) or the overflow menu icon (which opens the menu).

So I have a toolbar

I’m coding it to look like this.

//I do
mToolbar = (Toolbar) findViewById(R.id.toolbar) in code ;

private void initToolbar() {
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}

Now I need to change the images on these two icons.

How do I use the Compat v7 toolbar? I think I need to change the arrow that is visible when the box is open (Android 5.0).

How can I solve this problem?

Solution 1:

To change the navigation icon, you can use

Toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar) ;
setSupportActionBar(Toolbar) ;
toolbar.setNavigationIcon(R.drawable.my_icon) ;

You can use this method to change the overflow icon:

toolbar.setOverflowIcon(ContextCompat.getDrawable(this, R.drawable.ic_my_menu) ;

If you want to change the color of the icons, you can use

with the theme of the hardware component (for example, with the MaterialToolbar) :

With the theme AppCompatible :

You can also replace the overflow icon in the application theme with the ActionOverflowButtonStyle attribute :

With the theme of hardware components:

With the theme AppCompatible :

Solution 2:

mToolbar.setNavigationIcon(R.mipmap.ic_launcher);
mToolbar.setOverflowIcon(ContextCompat.getDrawable(this, R.drawable.ic_menu))

Solution 3:

For a good menu, it is possible:

public static setTintDrawable(drawable, @ColorInt int color) {
drawable.clearColorFilter();
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
drawable.invalidateSelf();
drawable wrapDrawable = DrawableCompat.wrap(drawable).mutate();
DrawableCompat.setTint(wrapDrawable, color);
return wrapDrawable;
}

And in your activities.

@General Boolean menu
onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_profile, menu);
Drawable send = menu.findItem(R.id.send);
Drawable msg = menu.findItem(R.id.message);
DrawableUtils.setTintDrawable(send.getIcon(), Color.WHITE);
DrawableUtils.setTintDrawable(msg.getIcon(), Color.WHITE);
return true;
}

Here’s the result:

Enter a description of the image here

Solution 4:

There is a simple, easy and better approach if we only need to change the color of the hamburger/back icon.

This is better because it only changes the color of the desired icon, while colorControlNormal and android:textColorSecondary can affect the other child views of the toolbar.

Solution no. 5:

If you want to change the symbols to Vector, create a new one.
, then in Activity.java :

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 the color of the vector icon, go to your XML vector…. file. In this case, it will be your_icon.xml, which will look like this:

Note that we used these attributes to set the color of the vector:

android:fillColor=@color/your_color

Edit: You cannot use a color from your color.XML file or anywhere else, the color must be shifted directly into the Vector XML…. file so it looks like this:

android:fillColor=#FFFFFFFFFF

Solution no. 6:

All of the above solutions worked for me in API 21 and beyond, but not in API 19 (KitKat). A little tweak did the trick for me in previous versions. Rate Widget.Holo instead of Widget.AppCompat.

Solution no. 7:

Insert the default theme in this line;

@color/my_color

Solution no. 8:

if you want to change the menu icons, the arrow icon (save/recycle) and the 3-dot icon, you can use android:tint

Solution no. 9:

What theme you used in the activity, add a line of code below.

for white

or

for black

or

Solution no. 10:

To change the color of the menu options, you can select

Replace the nice toCreateOptionsMenu (menu: Menu ?): Boolean {
menuInflater.inflate(R.menu.your_menu, menu)

menu ?.forEach {
it.icon.setTint(Color.your_color)
}

return where
}

Good luck!

 custom action bar androidandroid toolbar custom view examplesetsupportactionbar in fragmentandroid toolbar back buttonhow to get action bar in androidadd button in title bar androidandroidx toolbarandroid custom toolbar layout exampleandroid toolbar tutorialandroid.support.v7.widget.toolbar errorcustom toolbar android kotlinandroid material design status bar colorchange color primary dark androidstatus bar android studiolight status bar androidandroid toolbar example stackoverflowtoolbar in android javatpointandroidx.appcompat.widget.toolbar exampletoolbar with back button in android exampletoolbar android javatpointhow to change action bar icon color in androidchange toolbar home icon androidhow to change overflow menu icon in androidhow to change toolbar icon color androidtoolbar home icon change colorhow to change option menu icon color in androidandroid change three dots menu icon color programmaticallyhow to change navigation icon in android