1

I am trying to change the background color of the three dots menu on the toolbar programmatically, how can I change that at run time?

I don't want to change it in XML because It has to be changed at run time.

getSupportActionBar.setBackgroundDrawable(new ColorDrawable(getResources.getColor(R.color.red)))

The three dots needs to change color.

Tanveer Munir
  • 1,956
  • 1
  • 12
  • 27

1 Answers1

1

Change overflow icon is easy with support 23. Here is a method from Lorne Laliberte answer and here is you can also see this.

public static void setOverflowButtonColor(final Toolbar toolbar, final int color) {
    Drawable drawable = toolbar.getOverflowIcon();
    if(drawable != null) {
        drawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(drawable.mutate(), color);
        toolbar.setOverflowIcon(drawable);
    }
}

You can change your home as up passing your custom drawable...

getSupportActionBar().setHomeAsUpIndicator(R.drawable.your_drawable)

or changing its color

final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(Color.parseColor("#FFFFFF"), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);

Note: If you want to change more elements here is a good post to change all toolbar icons colors.

Tanveer Munir
  • 1,956
  • 1
  • 12
  • 27