Skip to content

Commit 88e2dd2

Browse files
ymarianafohrman
authored andcommitted
Update docs for MaterialCardView
PiperOrigin-RevId: 234983965
1 parent 7b628db commit 88e2dd2

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

docs/components/MaterialCardView.md

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,43 @@ be listed in the layout of the card and cannot be included in a `style` tag.
5858
</com.google.android.material.card.MaterialCardView>
5959
```
6060

61+
### Checkable Cards
62+
63+
Cards implement `Checkable` interface. In the default style,
64+
`@style/Widget.MaterialComponents.CardView`, the checked state shows a checked
65+
icon and changes the overlay color. A default way of switching to checked state
66+
is not provided, clients have to call `setChecked(boolean)` on the card. Setter
67+
for an `OnCheckedChangeListener` is also provided.
68+
69+
### Draggable Cards
70+
71+
Cards have a `dragged_state`. In the default style,
72+
`@style/Widget.MaterialComponents.CardView`, the dragged state has foreground
73+
and elevation changes to convey motion.
74+
The recommended way of using dragged state is via
75+
`androidx.customview.widget.ViewDragHelper`.
76+
77+
```java
78+
private class ViewDragHelperCallback extends ViewDragHelper.Callback {
79+
80+
/..../
81+
82+
@Override
83+
public void onViewCaptured(@NonNull View capturedChild, int activePointerId) {
84+
if (capturedChild instanceof MaterialCardView) {
85+
((MaterialCardView)view).setDragged(true);
86+
}
87+
}
88+
89+
@Override
90+
public void onViewReleased(@NonNull View releaseChild, float xVel, float yVel) {
91+
if (releaseChild instanceof MaterialCardView) {
92+
((MaterialCardView)view).setDragged(false);
93+
}
94+
}
95+
}
96+
```
97+
6198
### Material Styles
6299

63100
Using `MaterialCardView` with an updated Material theme
@@ -109,9 +146,13 @@ for a
109146
[`CardView`](https://developer.android.com/reference/android/support/v7/widget/CardView.html).
110147
The following additional attributes can be changed for a `MaterialCardView`:
111148

112-
Feature | Relevant attributes
113-
:------ | :------------------
114-
Border | `app:strokeColor`<br/>`app:strokeWidth`
149+
Feature | Relevant attributes
150+
:--------------- | :--------------------------------------------
151+
Border | `app:strokeColor`<br/>`app:strokeWidth`
152+
Checkable | `android:checkable`
153+
Checked Icon | `app:checkedIcon` <br/> `app:checkedIconTint`
154+
Foreground Color | `app:cardForegroundColor`
155+
Ripple Color | `app:rippleColor`
115156

116157
### Theme Attribute Mapping
117158

@@ -121,9 +162,13 @@ Border | `app:strokeColor`<br/>`app:strokeWidth`
121162
style="@style/Widget.MaterialComponents.CardView"
122163
```
123164

165+
The updated material style includes ripple when the card is clickable, checked
166+
state when the card is checkable, and stateListAnimator for dragged state.
167+
124168
Component Attribute | Default Theme Attribute Value
125-
--------------------- | -----------------------------
169+
--------------------- | --------------------------------
126170
`cardBackgroundColor` | `colorSurface`
171+
`shapeAppearance` | `shapeAppearanceMediumComponent`
127172
`strokeColor` | None
128173

129174
#### Legacy Material Style

0 commit comments

Comments
 (0)