Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 690
Zardoz Avatar asked Nov 24 '19 20:11

Zardoz


People also ask

What is colorSecondary?

This answer is not useful. Show activity on this post. 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.

What is color secondary android?

onSecondary. Color used for text and icons displayed on top of the secondary color. Color. onSurface. Color used for text and icons displayed on top of the surface color.

What is android Material theme?

A Material theme includes color, typography and shape parameters which you can adjust to get near-infinite variations of the components – all while maintaining their core anatomy and usability. On Android, Material Theming can be implemented using the Material Components (MDC) library, from version 1.1. 0 onwards.


3 Answers

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.

like image 55
Gabriele Mariotti Avatar answered Oct 07 '22 10:10

Gabriele Mariotti


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.

like image 41
Syed Ahmed Jamil Avatar answered Oct 07 '22 09:10

Syed Ahmed Jamil


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.

like image 20
Niladree Avatar answered Oct 07 '22 09:10

Niladree