Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does FAB's color depend on colorAccent?

According to doc, the color of the view defaults to our theme's colorAccent. I tried changing colorAccent in my styles resource file, but nothing happened:

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="colorAccent">#d81b60</item>
</style>

So I tried changing colorSecondary instead:

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="colorSecondary">#d81b60</item>
</style>

And it worked. So my question is does it really depend on colorAccent? If yes, when?

like image 918
Richard Avatar asked Feb 03 '20 11:02

Richard


1 Answers

Starting with the version 1.1.0 of the Material Components Library the default style of the FloatingActionButton is based on ?attr/colorSecondary:

  <style name="Widget.MaterialComponents.FloatingActionButton" parent="Widget.Design.FloatingActionButton">
    <item name="backgroundTint">?attr/colorSecondary</item>
  </style>

Starting with the version 1.2.0 of the Material Components Library the default style of the FloatingActionButton is:

    <style name="Widget.MaterialComponents.FloatingActionButton" parent="Widget.Design.FloatingActionButton">
        <item name="backgroundTint">@color/mtrl_fab_bg_color_selector</item>
        <!-- .... -->
    </style>

Starting from the version 1.2.0 the @color/mtrl_fab_bg_color_selector is based on the ?attr/colorSecondary:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:color="?attr/colorSecondary" android:state_enabled="true"/>
  <item android:alpha="0.12" android:color="?attr/colorOnSurface"/>
</selector>

In the version 1.0.0 the backgroundTint was based on ?attr/colorAccent:

  <style name="Widget.Design.FloatingActionButton" parent="android:Widget">
    <item name="backgroundTint">?attr/colorAccent</item>
    ...
  </style>
like image 129
Gabriele Mariotti Avatar answered Nov 20 '22 19:11

Gabriele Mariotti