Search code examples
androidandroid-layoutandroid-activityandroid-studioandroid-actionbar

How to set Toolbar background color in an activity to a color inside colors.xml file?


I have a color in my colors.xml file which I need to use for toolbar color

<resources>
    <color name="MAIN_A">#f16264</color>
</resources>

Now I need to use MAIN_A as a color for toolbar.


Solution

  • Use this code

    getSupportActionBar().setBackground(new ColorDrawable(getResources().getColor(R.color.white)));