Color by Actionbar

Asked

Viewed 72 times

1

I wonder how I can change the color of Actionbar dynamically ?

I’ve tried to take getSupportActionBar but I couldn’t get.

  • What have you tried? Do you have trial code? If so, add the question by clicking [Edit]

1 answer

3


You can do it like this:

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.BLUE));

Or so:

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.colorBlack)));
  • Good afternoon Luiz, it worked yes How can I set the colorPrimaryDark too ?

  • Good afternoon Luiz, it worked yes How can I set the colorPrimaryDark too ?

  • You can not change the color Primary dynamically. It is part of a theme and themes are immutable dynamically. You can have several predefined themes and changes dynamically. But this is outside the scope of your question, if my answer has served you, please mark as certain.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.