Canvas demo app
We will create a new project just to explore the topic of drawing with Canvas
. We will reuse what we have just learned and this time, we will also draw to the Bitmap
instance.
Creating a new project
Create a new project and call it Canvas Demo
. Choose the Empty Activity template.
In addition, we are going to be using the vanilla version of the Activity
class and the MainActivity
class will therefore extend Activity
instead of AppCompatActivity
as we have been using previously. This is simply because we no longer need the extra features provided by the AppCompatActivity
class.
Note
The complete code for this app can be found in the download bundle in the Chapter 20/Canvas Demo
folder.
Coding the Canvas demo app
To get started, edit the code in MainActivity.java
, including adding the import
directives and changing the version of the Activity
class that the MainActivity
class inherits from. Also notice in the next code that the call to the setContentView...