@@ -12,8 +12,13 @@ path: /catalog/cards/
12
12
[ Cards] ( https://material.io/components/cards/ ) contain content and actions about
13
13
a single subject.
14
14
15
- ![ Elevated card with a secondary title and Action 1 and Action 2 buttons in
16
- purple] ( assets/cards/cards_basic.png )
15
+ ![ "Cards on a screen"] ( assets/cards/cards_hero.png )
16
+
17
+ ## Contents
18
+
19
+ * [ Using cards] ( #using-cards )
20
+ * [ Card] ( #card )
21
+ * [ Theming] ( #theming-cards )
17
22
18
23
## Using cards
19
24
@@ -37,140 +42,7 @@ on it, so that the behavior can be accessible via screen readers such as
37
42
TalkBack. See the [ draggable card section] ( #making-a-card-draggable ) section
38
43
below for more info.
39
44
40
- ## Card
41
-
42
- On mobile, a [ card’s] ( https://material.io/components/cards/#specs ) default
43
- elevation is ` 1dp ` , with a raised dragged elevation of ` 8dp ` .
44
-
45
- ### Card examples
46
-
47
- API and source code:
48
-
49
- * ` MaterialCardView `
50
- * [ Class definition] ( https://developer.android.com/reference/com/google/android/material/card/MaterialCardView )
51
- * [ Class source] ( https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/card/MaterialCardView.java )
52
-
53
- _ ** Note:** You don't need to specify a style tag as long as you are using a
54
- Material Components Theme. If not, set the style to
55
- ` Widget.MaterialComponents.CardView ` ._
56
-
57
- #### Elevated card
58
-
59
- The following example shows an elevated card.
60
-
61
- ![ "Elevated card with a title, a secondary title, text, and Action 1 and Action
62
- 2 buttons in purple"] ( assets/cards/cards_elevated.png )
63
-
64
- ``` xml
65
- <com .google.android.material.card.MaterialCardView
66
- android : id =" @+id/card"
67
- android : layout_width =" match_parent"
68
- android : layout_height =" wrap_content"
69
- android : layout_margin =" 8dp" >
70
-
71
- <LinearLayout
72
- android : layout_width =" match_parent"
73
- android : layout_height =" wrap_content"
74
- android : orientation =" vertical" >
75
-
76
- <!-- Media -->
77
- <ImageView
78
- android : layout_width =" match_parent"
79
- android : layout_height =" 194dp"
80
- app : srcCompat =" @drawable/media"
81
- android : scaleType =" centerCrop"
82
- android : contentDescription =" @string/content_description_media"
83
- />
84
-
85
- <LinearLayout
86
- android : layout_width =" match_parent"
87
- android : layout_height =" wrap_content"
88
- android : orientation =" vertical"
89
- android : padding =" 16dp" >
90
-
91
- <!-- Title, secondary and supporting text -->
92
- <TextView
93
- android : layout_width =" wrap_content"
94
- android : layout_height =" wrap_content"
95
- android : text =" @string/title"
96
- android : textAppearance =" ?attr/textAppearanceHeadline6"
97
- />
98
- <TextView
99
- android : layout_width =" wrap_content"
100
- android : layout_height =" wrap_content"
101
- android : layout_marginTop =" 8dp"
102
- android : text =" @string/secondary_text"
103
- android : textAppearance =" ?attr/textAppearanceBody2"
104
- android : textColor =" ?android:attr/textColorSecondary"
105
- />
106
- <TextView
107
- android : layout_width =" wrap_content"
108
- android : layout_height =" wrap_content"
109
- android : layout_marginTop =" 16dp"
110
- android : text =" @string/supporting_text"
111
- android : textAppearance =" ?attr/textAppearanceBody2"
112
- android : textColor =" ?android:attr/textColorSecondary"
113
- />
114
-
115
- </LinearLayout >
116
-
117
- <!-- Buttons -->
118
- <LinearLayout
119
- android : layout_width =" wrap_content"
120
- android : layout_height =" wrap_content"
121
- android : layout_margin =" 8dp"
122
- android : orientation =" horizontal" >
123
- <com .google.android.material.button.MaterialButton
124
- android : layout_width =" wrap_content"
125
- android : layout_height =" wrap_content"
126
- android : layout_marginEnd =" 8dp"
127
- android : text =" @string/action_1"
128
- style =" ?attr/borderlessButtonStyle"
129
- />
130
- <com .google.android.material.button.MaterialButton
131
- android : layout_width =" wrap_content"
132
- android : layout_height =" wrap_content"
133
- android : text =" @string/action_2"
134
- style =" ?attr/borderlessButtonStyle"
135
- />
136
- </LinearLayout >
137
-
138
- </LinearLayout >
139
-
140
- </com .google.android.material.card.MaterialCardView>
141
- ```
142
-
143
- #### Outlined card
144
-
145
- The following example shows an outlined card.
146
-
147
- ![ "Outlined card with a title, a secondary title, text, and Action 1 and Action
148
- 2 buttons in purple"] ( assets/cards/cards_outlined.png )
149
-
150
- In the layout:
151
-
152
- ``` xml
153
- <com .google.android.material.card.MaterialCardView
154
- ...
155
- app : strokeWidth =" 1dp"
156
- app : strokeColor =" @color/stroke_color"
157
- app : cardElevation =" 0dp" >
158
-
159
- ...
160
-
161
- </com .google.android.material.card.MaterialCardView>
162
- ```
163
-
164
- In the stroke color (` stroke_color.xml ` ):
165
-
166
- ``` xml
167
- <selector xmlns : android =" http://schemas.android.com/apk/res/android" >
168
- <item android : color =" ?attr/colorPrimary" android : state_checked =" true" />
169
- <item android : alpha =" 0.12" android : color =" ?attr/colorOnSurface" android : state_checked =" false" />
170
- </selector >
171
- ```
172
-
173
- #### Making a card checkable
45
+ ### Making a card checkable
174
46
175
47
![ Elevated card with a checked button and a light purple overlay; secondary
176
48
title and Action 1 and Action 2 buttons] ( assets/cards/cards_checked.png )
@@ -202,7 +74,7 @@ card.setOnLongClickListener {
202
74
}
203
75
```
204
76
205
- #### Making a card draggable
77
+ ### Making a card draggable
206
78
207
79
![ Elevated card with a light grey overlay; secondary title and Action 1 and
208
80
Action 2 buttons] ( assets/cards/cards_dragged.png )
@@ -318,6 +190,142 @@ _**Note:** Cards also support a swipe-to-dismiss behavior through the use of
318
190
You can see an example
319
191
[ here] ( https://github.com/material-components/material-components-android/tree/master/catalog/java/io/material/catalog/card/CardSwipeDismissFragment.java ) ._
320
192
193
+ ## Card
194
+
195
+ On mobile, a [ card’s] ( https://material.io/components/cards/#specs ) default
196
+ elevation is ` 1dp ` , with a raised dragged elevation of ` 8dp ` .
197
+
198
+ ![ Elevated card with a secondary title and Action 1 and Action 2 buttons in
199
+ purple] ( assets/cards/cards_basic.png )
200
+
201
+ ### Card examples
202
+
203
+ API and source code:
204
+
205
+ * ` MaterialCardView `
206
+ * [ Class definition] ( https://developer.android.com/reference/com/google/android/material/card/MaterialCardView )
207
+ * [ Class source] ( https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/card/MaterialCardView.java )
208
+
209
+ _ ** Note:** You don't need to specify a style tag as long as you are using a
210
+ Material Components Theme. If not, set the style to
211
+ ` Widget.MaterialComponents.CardView ` ._
212
+
213
+ #### Elevated card
214
+
215
+ The following example shows an elevated card.
216
+
217
+ ![ "Elevated card with a title, a secondary title, text, and Action 1 and Action
218
+ 2 buttons in purple"] ( assets/cards/cards_elevated.png )
219
+
220
+ ``` xml
221
+ <com .google.android.material.card.MaterialCardView
222
+ android : id =" @+id/card"
223
+ android : layout_width =" match_parent"
224
+ android : layout_height =" wrap_content"
225
+ android : layout_margin =" 8dp" >
226
+
227
+ <LinearLayout
228
+ android : layout_width =" match_parent"
229
+ android : layout_height =" wrap_content"
230
+ android : orientation =" vertical" >
231
+
232
+ <!-- Media -->
233
+ <ImageView
234
+ android : layout_width =" match_parent"
235
+ android : layout_height =" 194dp"
236
+ app : srcCompat =" @drawable/media"
237
+ android : scaleType =" centerCrop"
238
+ android : contentDescription =" @string/content_description_media"
239
+ />
240
+
241
+ <LinearLayout
242
+ android : layout_width =" match_parent"
243
+ android : layout_height =" wrap_content"
244
+ android : orientation =" vertical"
245
+ android : padding =" 16dp" >
246
+
247
+ <!-- Title, secondary and supporting text -->
248
+ <TextView
249
+ android : layout_width =" wrap_content"
250
+ android : layout_height =" wrap_content"
251
+ android : text =" @string/title"
252
+ android : textAppearance =" ?attr/textAppearanceHeadline6"
253
+ />
254
+ <TextView
255
+ android : layout_width =" wrap_content"
256
+ android : layout_height =" wrap_content"
257
+ android : layout_marginTop =" 8dp"
258
+ android : text =" @string/secondary_text"
259
+ android : textAppearance =" ?attr/textAppearanceBody2"
260
+ android : textColor =" ?android:attr/textColorSecondary"
261
+ />
262
+ <TextView
263
+ android : layout_width =" wrap_content"
264
+ android : layout_height =" wrap_content"
265
+ android : layout_marginTop =" 16dp"
266
+ android : text =" @string/supporting_text"
267
+ android : textAppearance =" ?attr/textAppearanceBody2"
268
+ android : textColor =" ?android:attr/textColorSecondary"
269
+ />
270
+
271
+ </LinearLayout >
272
+
273
+ <!-- Buttons -->
274
+ <LinearLayout
275
+ android : layout_width =" wrap_content"
276
+ android : layout_height =" wrap_content"
277
+ android : layout_margin =" 8dp"
278
+ android : orientation =" horizontal" >
279
+ <com .google.android.material.button.MaterialButton
280
+ android : layout_width =" wrap_content"
281
+ android : layout_height =" wrap_content"
282
+ android : layout_marginEnd =" 8dp"
283
+ android : text =" @string/action_1"
284
+ style =" ?attr/borderlessButtonStyle"
285
+ />
286
+ <com .google.android.material.button.MaterialButton
287
+ android : layout_width =" wrap_content"
288
+ android : layout_height =" wrap_content"
289
+ android : text =" @string/action_2"
290
+ style =" ?attr/borderlessButtonStyle"
291
+ />
292
+ </LinearLayout >
293
+
294
+ </LinearLayout >
295
+
296
+ </com .google.android.material.card.MaterialCardView>
297
+ ```
298
+
299
+ #### Outlined card
300
+
301
+ The following example shows an outlined card.
302
+
303
+ ![ "Outlined card with a title, a secondary title, text, and Action 1 and Action
304
+ 2 buttons in purple"] ( assets/cards/cards_outlined.png )
305
+
306
+ In the layout:
307
+
308
+ ``` xml
309
+ <com .google.android.material.card.MaterialCardView
310
+ ...
311
+ app : strokeWidth =" 1dp"
312
+ app : strokeColor =" @color/stroke_color"
313
+ app : cardElevation =" 0dp" >
314
+
315
+ ...
316
+
317
+ </com .google.android.material.card.MaterialCardView>
318
+ ```
319
+
320
+ In the stroke color (` stroke_color.xml ` ):
321
+
322
+ ``` xml
323
+ <selector xmlns : android =" http://schemas.android.com/apk/res/android" >
324
+ <item android : color =" ?attr/colorPrimary" android : state_checked =" true" />
325
+ <item android : alpha =" 0.12" android : color =" ?attr/colorOnSurface" android : state_checked =" false" />
326
+ </selector >
327
+ ```
328
+
321
329
### Anatomy and key properties
322
330
323
331
A card has a container and an optional thumbnail, header text, secondary text,
0 commit comments