fgoogle fgoogle - 1 year ago 112
Android Question

How to use a resource color id with .setBackgroundDrawable

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

((AppCompatActivity) getActivity())


What should be put inside the brackets in order to refer to

Answer Source

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)));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download