|
Android
Development Starter Guide using Android Studio Drawing Step 1: Drawings can be contained in a View object. Create a child class of View to add to your screen. ![]() Lets call this class MyDrawing. Make sure to extends View and add a constructor with the following criteria in order for the layout editor to work properly. import android.content.Context; Step 2: In the MyDrawing class, override the onDraw(Canvas canvas) method. @Override Step 3: Override the onDraw(Canvas canvas) method. Make an instance variable of Paint. Now you can draw things in the onDraw method using canvas and paint to set color. public class MyDrawing extends View { Step 4: Add the view to your main activitly layout xml in Design view. Drag in the Custom->CustomView object from the left palette and select the MyDraw class we created. ![]() Ignore the rendering error as you will see the results when you run the program. Step 5: Run it and should see the following. |