pulp_fiction pulp_fiction - 1 year ago 113
Android Question

Unable to set TextView background color in a RecyclerView

I have a RecyclerView which contains TextView. The holder code is below:

private class PhotoHolder extends RecyclerView.ViewHolder {
private TextView mTitleTextView;
public PhotoHolder(View itemView) {
mTitleTextView = (TextView) itemView;
public void bindGalleryItem(GalleryItem item) {
//--------------TEST CODE----------------

Now, the line
works as expected but I also wanted to change background of the
. So, I tried calling the
method but even the call to invalidate and requestLayout don't set any background color.

Does anyone know a way to ensure setting of the background color? Is this the right place to set the color? Why is it not setting?

Also, I want to do this programmatically.

Answer Source

It should be


or to set the Text Color you can use the below


Define your specific color in colors.xml

<color name="colorOne">#E60000</color>
<color name="colorTwo">#D3D3D3</color>

Color code are standards across different development activities. Android framework should understand the parameter value that you are planning to set to a view. Reference Link for Graphics color code

You can use softwares similar to this to find the color code

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download