-
Notifications
You must be signed in to change notification settings - Fork 378
BasicImageButtonsCard
BasicImageButtonsCard is a Card that shows an image to the left, and to the right it offers:
- A title
- A description
- Two buttons
Card card = new Card.Builder(this)
.withProvider(new CardProvider())
.setLayout(R.layout.material_basic_image_buttons_card_layout)
.setTitle("Card number 3")
.setTitleGravity(Gravity.END)
.setDescription("Lorem ipsum dolor sit amet")
.setDescriptionGravity(Gravity.END)
.setDrawable(R.drawable.dog)
.setDrawableConfiguration(new CardProvider.OnImageConfigListener() {
@Override
public void onImageConfigure(@NonNull RequestCreator requestCreator) {
requestCreator.fit();
}
})
.addAction(R.id.left_text_button, new TextViewAction(this)
.setText("Izquierda")
.setTextResourceColor(R.color.black_button)
.setListener(new OnActionClickListener() {
@Override
public void onActionClicked(View view, Card card) {
Toast.makeText(mContext, "You have pressed the left button", Toast.LENGTH_SHORT).show();
card.getProvider().setTitle("CHANGED ON RUNTIME");
}
}))
.addAction(R.id.right_text_button, new TextViewAction(this)
.setText("Derecha")
.setTextResourceColor(R.color.orange_button)
.setListener(new OnActionClickListener() {
@Override
public void onActionClicked(View view, Card card) {
Toast.makeText(mContext, "You have pressed the right button on card " + card.getProvider().getTitle(), Toast.LENGTH_SHORT).show();
card.dismiss();
}
}))
.endConfig()
.build();
For title and description, you only need to call the setTitle(String title)
and setDescription(String description)
methods
BasicImageButtonsCard card = new BasicImageButtonsCard(context);
card.setTitle("Your title");
card.setDescription("Your description");
In order to set the image, you need to call the setBitmap()
method, and pass it one of the following:
- A
Bitmap
- A
Context
plus a resource id (such as R.drawable.my_icon) - A
Drawable
The text shown in both buttons can also be set, just by calling BasicImageButtonsCard.setLeftButtonText(String text)
(or its right equivalent).
card.setLeftButtonText("LEFT");
card.setRightButtonText("RIGHT");
You can also define behaviours for the button pressing. You only need to call BasicImageButtonsCard.setOnLeftButtonPressedListener(OnButtonPressListener)
(or its equivalent for the right button) and define its behaviour.
As you can see, you will receive the View and the Card attached to that View, in order to recover the data from it.
Example:
card.setOnRightButtonPressedListener(new OnButtonPressListener() {
@Override
public void onButtonPressedListener(View view, Card card) {
Toast.makeText( mContext,
"You have pressed the right button",
Toast.LENGTH_SHORT
).show();
}
});