Created
September 2, 2014 17:41
-
-
Save gabrielemariotti/4200d059f100cdf832f6 to your computer and use it in GitHub Desktop.
A simple gist to build a MaterialCard with cardslib v2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create a Card, set the title over the image and set the thumbnail | |
MaterialLargeImageCard card = new MaterialLargeImageCard(getActivity()); | |
card.setTextOverImage("Italian Beaches"); | |
card.setDrawableCardThumbnail(R.drawable.sea); | |
//Set the title and subtitle in the card | |
card.setTitle("This is my favorite local beach"); | |
card.setSubTitle("A wonderful place"); | |
// Set supplemental actions | |
TextSupplementalAction t1 = new TextSupplementalAction(getActivity(), R.id.text1); | |
t1.setOnActionClickListener(new BaseSupplementalAction.OnActionClickListener() { | |
@Override | |
public void onClick(Card card, View view) { | |
Toast.makeText(getActivity()," Click on Text SHARE ",Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
card.addSupplementalAction(t1); | |
TextSupplementalAction t2 = new TextSupplementalAction(getActivity(), R.id.text2); | |
t2.setOnActionClickListener(new BaseSupplementalAction.OnActionClickListener() { | |
@Override | |
public void onClick(Card card, View view) { | |
Toast.makeText(getActivity()," Click on Text LEARN ",Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
card.addSupplementalAction(t2); | |
//Set the layout for supplemental actions | |
card.setLayout_supplemental_actions_id(R.layout.carddemo_native_material_supplemental_actions_large); | |
//Very important call: build the card | |
card.build(); | |
//Set card in the CardViewNative | |
CardViewNative cardView = (CardViewNative) getActivity().findViewById(R.id.carddemo_largeimage_text); | |
cardView.setCard(card); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this great library. I want this Material Card to place under RecyclerView. To do that somehow I need to pass the layout information i.e. R.layout.native_material_largeimage_text_card
But if I pass it in constructor the layout isn't coming. Also in line 4, the drawable method changed to card.setDrawableIdCardThumbnail(R.drawable.sea);