Views

A view is a layout element that occupies a set area of the screen and is responsible for drawing and event handling. View is the base class for UI elements or widgets such as text fields, input fields, and buttons. All views extend the View class.

Views can be created within an XML layout in a source file. Consider the following code:

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Roll the dice!"/>

Besides creating views directly in a layout file, they can also be created programmatically within program files. For example, a text view can be made by creating an instance of the TextView class and passing a context to its constructor. This is demonstrated in the following code snippet: ...

Get Kotlin Programming By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.