-1

I have this file in my code, it is used as a card background for my RecyclerView Item.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/primary"
        android:id="@+id/background_color"/>

    <item android:top="200dp"
        android:bottom="-300dp"
        android:left="0dp"
        android:right="-300dp">
        <rotate
            android:fromDegrees="-10"
            android:pivotX="0%"
            android:pivotY="100%">
            <shape
                android:shape="rectangle">
                <solid
                    android:color="@color/white"/>
            </shape>
        </rotate>
    </item>
</layer-list>

I want to change the color of id background_color. How can I do this since I can't seem to understand how to cast it to a View.

Help appreciated!

Varun Joshi
  • 599
  • 2
  • 9
  • 24
  • Possible duplicate of [How to change colors of a Drawable in Android?](https://stackoverflow.com/questions/1309629/how-to-change-colors-of-a-drawable-in-android) – Martin Marconcini May 02 '18 at 17:25
  • Hey @MartinMarconcini not a duplicate, I want to get an id of a layer inside my layer list. Pretty sure it's not very difficult but just unable to understand – Varun Joshi May 02 '18 at 18:51

1 Answers1

0

you can try this,

    TextView textview = (TextView)findViewById(R.id.textview);

    GradientDrawable backgroundcolor = (GradientDrawable) textView.getBackground();

    backgroundcolor.setColor(getResources().getColor(R.color.any_color));

In place of textview you can set your view in which you want to change background.

In your code you can replace textview with your item(item's textview).

Janvi Vyas
  • 732
  • 5
  • 16