medihack
medihack

Reputation: 16627

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?

Upvotes: 13

Views: 6551

Answers (3)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363895

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.

Upvotes: 11

Syed Ahmed Jamil
Syed Ahmed Jamil

Reputation: 2111

Yes, I do believe colorSecondary is the new term for colorAccent and are interchangeable because if you read the docs specifically the definition of secondary color it says

A secondary color provides more ways to accent and distinguish your product. Having a secondary color is optional, and should be applied sparingly to accent select parts of your UI.

I guess just from that statement it is pretty clear that they both have the same purpose.

Upvotes: 5

Niladree
Niladree

Reputation: 526

As per the material design documentation, the primary color and the secondary color are actually the primaryColor and accentColor in Android Studio. But if more variations are required then the secondaryColor can be used.

So prefer accentColor tag in Android Studio to define the secondary color from material design documentation.

You can try out some material palettes like https://www.materialpalette.com to understand the behaviour.

Upvotes: 1

Related Questions