Card

Cards are used to group related items. They allow complex datasets to be broken down into individual, distinct areas for easy consumption.

Card

Maven Central Class reference Source code

Default

Day Night
Card component Card component - dark mode

Corner style large

Day Night
Corner style large Card component Corner style large Card component - dark mode

Selected

Day Night
Selected Card component Selected Card component - dark mode

With divider and corner style large

Day Night
With divider and corner style large Card component With divider and corner style large Card component - dark mode

With divider arranged vertically

Day Night
With divider arranged verticy Card component With divider arranged verticy Card component - dark mode

With divider without padding

Day Night
With divider without padding Card component With divider without padding Card component - dark mode

With divider

Day Night
With divider Card component With divider Card component - dark mode

Without padding

Day Night
Without padding Card component Without padding Card component - dark mode

Installation

Backpack Android is available through Maven Central. Check the main Readme for a complete installation guide.

Usage

BpkCardView is an extension of CardView in com.android.support:cardview-v7

The Card component can be used in both XML and Kotlin

Example of a padded and focused card in XML


                                                
                                                 <net.skyscanner.backpack.card.BpkCardView
                                                    android:layout_width="match_parent"
                                                    android:layout_height="wrap_content"
                                                    android:clickable="true"
                                                    android:focusable="true"
                                                    android:foreground="?android:attr/selectableItemBackground"
                                                    app:elevationLevel="focused"
                                                    app:cornerStyle="small">
                                                
                                                    <net.skyscanner.backpack.text.BpkText
                                                      android:layout_width="match_parent"
                                                      android:layout_height="match_parent"
                                                      android:text="@string/stub_md" />
                                                
                                                  </net.skyscanner.backpack.card.BpkCardView>

Example of a padded and focused card in Kotlin


                                                
                                                import net.skyscanner.backpack.card.BpkCardView
                                                
                                                BpkCardView(context).apply {
                                                   padded = true
                                                   elevationLevel = BpkCardView.ElevationLevel.Focused
                                                   cornerStyle = BpkCardView.CornerStyle.SMALL
                                                }

Properties

Property PropType Required Default Value
padded Boolean false true
cornerStyle CornerStyle: Small, Large false Small
elevationLevel ElevationLevel: None, Default, Focused false Default

Accessibility

Consider if your card should be atomic or non-atomic. If the copy inside your card is lengthy, consider making it non-atomic and providing a CTA inside. The entire card will still be clickable/tappable, but will be ignored by TalkBack.

A clickable & focusable card is atomic by default, whereas a non-clickable/focusable card is non-atomic. To change that set the importantForAccessibility property to yes for atomic cards and no for non-atomic cards.