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"
android:orientation="vertical"
android:background="#009968"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
Changing Activity Title
The activity title displaye in the ToolBar can be changed programmatically using the Title
property defined in the Android.App.Acrivity
.
public string Title { get; set; }
<pre><code>You can both get and set the color. Let's see how to set it:
```c#
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView (Resource.Layout.Main);
//here's the custom title
this.Title = "My Custom Title";
}
}</code></pre>