Skip to Content
Native Mobile Development
book

Native Mobile Development

by Shaun Lewis, Mike Dunn
November 2019
Intermediate to advanced
394 pages
9h 44m
English
O'Reilly Media, Inc.
Content preview from Native Mobile Development

Chapter 3. Custom Components

While both Android and iOS provide a large number of widgets and components out of the box, there’s not always parity, and it’s very likely you’ll want to create your own at some point. You might want a date or color picker with custom look or behavior, a switch or toggle with a built-in label, data visualization components like charts and graphs, or something as simple as a configurable label and icon that’s suited just for your app.

Whatever the need, there’s a pretty good chance you can create it in either framework—but the process is very different and can be surprisingly arcane.

Tasks

In this chapter, you’ll learn:

  1. How to create a custom view.

  2. How to use a custom view.

Android

Since most layouts in Android apps are created with XML data, getting your custom component to accept and react appropriately to arbitrary properties is something you’ll probably want to offer. For example, if you were to create a custom color picker, you’d probably want to offer a default color to start with, or perhaps even a specific color space like HSL or RGB.

Since XML resources are compiled, you’ll need to make sure the system recognizes the extra properties you allow on your component and what values are valid. For example, if you add a color attribute, you wouldn’t want to accept a dimension value—you’d want only valid colors, or perhaps color resource IDs, to be accepted. If a user tries to enter an invalid value format, the program will fail to compile, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pro iPhone Development with SwiftUI: Design and Manage Top Quality Apps

Pro iPhone Development with SwiftUI: Design and Manage Top Quality Apps

Wallace Wang
Ionic in Action

Ionic in Action

Jeremy Wilken
What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz

Publisher Resources

ISBN: 9781492052869Errata PageSupplemental Content