I have the following two Drawables and Layout:
<?xml version="1.0" encoding="utf-8" ?>
<inset xmlns:android="http://schemas.android.com/apk/res/android" android:insetLeft="2dp" android:insetTop="26dp" android:insetRight="2dp" android:insetBottom="26dp">
<shape android:shape="rectangle">
<size android:height="2dp"/>
<solid android:color="@color/Black"/>
</shape>
</inset>
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:gravity="fill" android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="28dp">
<shape android:shape="rectangle">
<size android:height="26dp"/>
<solid android:color="@color/DarkOrange"/>
</shape>
</item>
<item android:gravity="fill" android:left="2dp" android:top="26dp" android:right="2dp" android:bottom="26dp">
<shape android:shape="rectangle">
<size android:height="2dp"/>
<solid android:color="@color/Black"/>
</shape>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="0dp" android:background="@drawable/pointsperturndivider" tools:ignore="HardcodedSize">
<TextView android:id="@+id/txtPoints" style="@style/ItemTextView" android:layout_height="54dp" android:paddingBottom="27dp" tools:text="-2147483648"/>
<TextView android:id="@+id/txtTotal" style="@style/ItemTextView" android:layout_height="54dp" android:paddingTop="27dp" tools:text="-2147483648"/>
</FrameLayout>
In my code, I want to dynamically set the Background property of the Layout to one of the Drawables using SetBackgroundResource. However, this does not seem to work. If I set android:background in the xml of the Layout, it works fine, but I need to change it in code. It also works fine when I use a Color resource instead of a Drawable resource. I also tried using Application.Context.GetDrawable to assign a value to the Background property, but this did not work either. How do I set the Background to a Drawable in code?


