如何将活动中的工具栏背景颜色设置为colors.xml文件中的颜色?

5 android android-layout android-activity android-actionbar android-studio

我的colors.xml文件中有一种颜色需要用于toolbar颜色

<resources>
    <color name="MAIN_A">#f16264</color>
</resources>
Run Code Online (Sandbox Code Playgroud)

现在我需要MAIN_A用作颜色toolbar.

小智 13

使用此代码

getSupportActionBar().setBackground(new ColorDrawable(getResources().getColor(R.color.white)));
Run Code Online (Sandbox Code Playgroud)