Material3 action bar doesn't allow to set background color programmatically

26 views Asked by At

Trying to set a custom color for an certain Activity programmatically, but action bar doesn't react even when set setBackgroundDrawable(null). Any thoughts? Thanks

Style:

<style name="Theme.App" parent="Theme.Material3.DayNight">
    <item name="toolbarStyle">@style/ToolbarStyle</item>
</style>

<style name="ToolbarStyle" parent="Widget.Material3.Toolbar">
    <item name="android:background">@color/material3_primary</item>
    <item name="titleTextColor">@color/white</item>
    <item name="navigationIcon">@drawable/ic_nav_back_dark_theme</item>
    <item name="theme">@style/ToolbarTheme</item>
</style>

<style name="ToolbarTheme">
    <item name="colorControlNormal">@color/white</item>
</style>

Activity:

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    title = "Temp"
    supportActionBar?.setBackgroundDrawable(ColorDrawable(Color.parseColor("#0000ff"))) //it doesn't work
}
0

There are 0 answers