0

I moved recently from Theme.AppCompat to Theme.MaterialComponents but I can't understand how to orgnaize colors.

<style name="Theme.Test" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/orange</item>
        <item name="colorPrimaryVariant">@color/red</item>
        <item name="colorOnPrimary">@color/yellow</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/green</item>
        <item name="colorSecondaryVariant">@color/black</item>
        <item name="colorOnSecondary">@color/white</item>
    </style>

For example why buttons take orange background color but background of cardview not take orange color?

Can someone explain to me more about these variables colorPrimary , colorPrimaryVariant , colorOnPrimary , colorSecondary , colorSecondaryVariant and colorOnSecondary

Is there any offical documentation?

Taha Sami
  • 1,565
  • 1
  • 16
  • 43

4 Answers4

2

You can refer to the following documentation: https://material.io/develop/android/theming/color

  • colorPrimary: The color displayed most frequently across your app’s screens and components. This color should pass accessibilty guidelines for text / iconography when drawn on top of the surface or background color.
  • colorPrimaryVariant: A tonal variation of the primary color.
  • colorOnPrimary: A color that passes accessibility guidelines for text/iconography when drawn on top of the primary color.
  • colorSecondary: The secondary branding color for the app, usually an accented complement to the primary branding color.
  • colorSecondaryVariant: A tonal variation of the secondary color.
  • colorOnSecondary: A color that passes accessibility guidelines for text/iconography when drawn on top of the secondary color.

You can also refer to this SO: https://stackoverflow.com/a/45879575/9246764

David Lee
  • 665
  • 7
  • 20
1

If you're looking for specifics about each component, the material.io documentation usually provides information about the default values for various attributes.

For example, the documentation for MaterialCardView specifies that the default app:cardBackgroundColor is ?attr/colorSurface.

Henry Twist
  • 5,666
  • 3
  • 19
  • 44
0

Take a look at the material sites official docs on using these themes in Android

https://material.io/develop/android/docs/getting-started

DevWithZachary
  • 3,545
  • 11
  • 49
  • 101
0

Okay so you should now use components from the Material theme. For example if you just want to Use a textview and apply the material theme on it You should be using it the way they suggest. For example for the textview you should use it

 <com.google.android.material.textfield.TextInputLayout

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="First Name"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    app:hintTextColor="@color/black">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/fName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

</com.google.android.material.textfield.TextInputLayout>

I think you are not using the card view from the material theme. Just check the official doc. https://material.io/components/cards

AlixaProDev
  • 472
  • 1
  • 5
  • 13