Hello,
Welcome to our Microsoft Q&A platform!
I make a test with FrameLayout
, set the background resource dynamically with following code.
I use following drawable called pointsperturndivider.xml
<?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>
Then I set this drawable to FrameLayout
after Button clicked
public class MainActivity : AppCompatActivity
{
FrameLayout frameLayout1;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
Button button1 = FindViewById<Button>(Resource.Id.button1);
button1.Click += Button1_Click;
frameLayout1 = FindViewById<FrameLayout>(Resource.Id.frameLayout1);
}
private void Button1_Click(object sender, System.EventArgs e)
{
// throw new System.NotImplementedException();
frameLayout1.SetBackgroundResource(Resource.Drawable.pointsperturndivider);
}
Here is running screenshot.
Before Button clicked.
After Button clicked
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.