Skip to Content
Android 9 Development Cookbook - Third Edition
book

Android 9 Development Cookbook - Third Edition

by Rick Boyer
October 2018
Intermediate to advanced
464 pages
15h 17m
English
Packt Publishing
Content preview from Android 9 Development Cookbook - Third Edition

How to do it...

We will create a new class for our custom component to derive from the Android View class. Our custom component could be a subclass of an existing class, such as the activity, but we will create it in a separate file to make it easier to maintain. Here are the steps:

  1. Start by creating a new Java class and calling it CustomView. This is where we will implement our custom component, as described in the Introduction.
  2. Change the class constructor so it extends View. It should look as follows:
public class CustomView extends View {
  1. Define a Paint object for the class, which will be used in onDraw():
final Paint mPaint = new Paint();
  1. Create a default constructor, which requires the activity Context, so we can inflate the view. ...
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

Android Application Development Cookbook - Second Edition

Android Application Development Cookbook - Second Edition

Rick Boyer, Kyle Mew
Android High Performance Programming

Android High Performance Programming

Enrique López Mañas, Diego Grancini
Android Things Projects

Android Things Projects

Francesco Azzola

Publisher Resources

ISBN: 9781788991216Supplemental Content