Reputation: 53
I use v7 toolbars (android.support.v7.widget.Toolbar) throughout my application. There is an easy method for setting the background color:
mToolbar.setBackgroundColor(Color.BLACK); // works!
But there is no method for getting the background color:
mToolbar.getBackgroundColor(); // Cannot Resolve Method
I want to get the background color of the toolbar so I can check if the toolbar is white. If it is white, I want to change the color of my menu icons, which are by default white, to black.
What would be the easiest way of getting the toolbar background color, if we can assume I've set it programmatically with setBackgroundColor()?
Upvotes: 3
Views: 5745
Reputation: 11695
int color = ((ColorDrawable) mToolbar.getBackground()).getColor();
// do your stuff
Upvotes: 13