Search code examples
androidandroid-themematerial-componentsmaterial-components-android

colorAccent or colorSecondary with Material Component theme


When creating a new app using the wizard of Android Studio a theme derived from Theme.MaterialComponents.Light.DarkActionBar is used and a colorAccent is set. On the other side the official documentation uses colorSecondary and doesn't mention colorAccent at all. Are both interchangeable? What to prefer?


Solution

  • The Theme.MaterialComponents uses the colorSecondary as described in the material guidelines and in the official doc. All the components defined in the library uses this attribute.

    However, in the library, there are also the Bridge themes which inherit from AppCompat themes and you can use them, if you cannot change your theme to inherit from a Material Components theme.
    These themes inherit from AppCompat themes defining the new Material Components theme attributes for you.

    You can check the bridge theme in the library:

    <style name="Base.V14.Theme.MaterialComponents.Light" parent="Base.V14.Theme.MaterialComponents.Light.Bridge">
    
      <!-- Colors -->
      <item name="colorAccent">?attr/colorSecondary</item>
    

    Here you can find the mapping between colorSecondary and the colorAccent for these themes.