0

I am trying to color my toolbar and status bar with two colors I have defined in the colors.xml file.

((AppCompatActivity) getActivity())
                .getSupportActionBar()
                .setBackgroundDrawable(?);


window.setStatusBarColor(?);

What should be put inside the brackets in order to refer to R.color.a and R.color.b ?

fgoogle
  • 79
  • 9

2 Answers2

5

Pass RGB value of the color

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.rgb(248, 248, 248)));

To pass Resourse id

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(getContext(),R.color.primary)));
randy
  • 765
  • 7
  • 24
0

It should be setBackgroundResource(), and not a drawable.

EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428