Defining Custom Views in Android
Learn to define and use custom views in Android.
Introduction
In our previous lesson, we talked about layouts and views provided by the framework that can be used to render the desired layout. While in most cases we’ll create layouts using a combination of views and view groups to achieve the desired UI, we might come across a use case where we need to create customized views based on our requirements. For this lesson, let’s take an example of a view that accepts two strings as input and renders them as title and subtitle, as shown in the image below.
You might be wondering why we don’t create a layout with two TextView
classes to render this kind of UI. That’s what we would usually do, but consider a case where we need something like this on more than one screen with minor customizations. For example, on some screens, we ...