O'Reilly logo

Xamarin Mobile Development for Android Cookbook by Matthew Leibowitz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using custom views with layouts

One of the most important parts is the user interface, as it is the most visible part of an app. When we create apps for Android devices, sometimes we may need to create custom views.

How to do it...

Creating a new UI control involves creating a new type, inheriting either directly or indirectly from one of the View types. Here's how it's done:

  1. If we want to create more advanced button control, we must create a new type inheriting from the Button type. We also need to ensure that the namespace is user friendly as it will be used in the layout files:
    namespace XamarinCookbook.Views {
      public class TimedButton : Button {
      }
    }
  2. Now we can implement the functionality that this button provides:
    public int Interval { get; set; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required