I have the following use case: using a RecyclerView with a custom adapter for listing a simple set of data (each row has something like an icon, a title, and a description). Think of your favorite email or newsfeed app and this is most likely the same visually.
I've reached the point where I need to stylize some key elements from the list quite differently to indicate a special situation - that they are "unread" or that they are "recommended" (e.g. with a different background color, the title font becomes bold, the icon is made larger, the description is hidden, etc).
All of these variations, being purely representation/visual, I have followed the good practices and defined them as 2 different <style>
blocks in the values/styles.xml
file. However, I am having a hard time applying one of these 2 styles to the row in the onBindViewHolder()
method of the adapter, based on some programmatical condition.
(Of course, I can go down the bad way and modify the styling programmatically by manually calling setBackgroundColor()
etc on each individual View, but this seems like an ugly workaround for a seemingly trivial problem; additionally, this way we are skipping all of the benefits the .xml styling provides like resolution or locale specific styles).