Xamarin Android - Activity Customizations

January 5, 2018 Oclemy Xamarin Activity 0 minutes, 54 seconds

Activities are fundamental components in android. They represent a screen with UI widgets as well as data.

It's important therefore to know how to customize activities.

Let's look at some of the simple ways activities can be customized:

Changing Background Color

We can change background color of an activity in the layout xml via the android:background="" element. All you need to do is add it in the root tag of your layout as below:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"


Activity Background Color

Changing Activity Title

The activity title displaye in the ToolBar can be changed programmatically using the Title property defined in the Android.App.Acrivity. ```c# public string Title { get; set; }

You can both get and set the color. Let's see how to set it:

    public class MainActivity : Activity
        protected override void OnCreate(Bundle bundle)
             SetContentView (Resource.Layout.Main);

            //here's the custom title
            this.Title = "My Custom Title";

Activity Background Color