airbnb / epoxy

Epoxy is an Android library for building complex screens in a RecyclerView
https://goo.gl/eIK82p
Apache License 2.0
8.5k stars 733 forks source link

Carousel background color #820

Closed dbof10 closed 5 years ago

dbof10 commented 5 years ago

Screenshot 2019-09-06 at 10 05 22 PM

This is my Carousel. Is the any way to set background color instead of setting its parent view?

reavcn commented 5 years ago

Hi @dbof10 ,

if I got you right, you can use onBind to set a background color for your carousel.

carousel {
    id(Model.TAG + "carousel")
    onBind { _, view, _ ->
        view.setBackgroundColor(ContextCompat.getColor(activity!!, R.color.YOUR_COLOR))
    }
    withModelsFrom(...) { ... ->
        // your models here
    }
}

I hope this answer your question!

elihart commented 5 years ago

while it works, I don't recommend using the onBind callback to style views. View styling should be done within the view, or with something like Paris (https://github.com/airbnb/epoxy/wiki/Paris-Integration-(Dynamic-Styling)).

In terms of carousels and color styling go though, this is no different from how a normal recyclerview works. a model's bind function is equivalent to a vanilla RecyclerView adapter's onBindViewHolder, and all styling can be done there