What is Graphics

Android graphics provides the low level graphics tool like canvas , color filters, points, and rectangles that let you drawing to the screen directly..

In my prgram run the app it will show you the circle at the center of the screen with red color.Pls see the image.


In this section i am going to show the graphics with practical example.

First open the android studio and create a project and give the name of your project like GraphicsDemo.

The screenshots of the program is as follows:

media image media image

You do not have need to drag and drop the widgets from pallet. Open the activity_main.xml file and code look like this

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"


Open the MainActivity.java file and write code look like this.

package com.example.niitpc.myapplication;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.speech.tts.TextToSpeech;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;

import java.util.Locale;

public class MainActivity extends AppCompatActivity  {
    VideoView videoView;
    MediaController mediaController;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
        setContentView(new MyView(this) );

   public class MyView extends  View{

        public MyView(Context context)

       protected void onDraw(Canvas canvas) {

           Paint paint=new Paint();
           int x=getWidth();
           int y=getHeight();
           int radious=100;
           paint.setStyle( Paint.Style.FILL );
           paint.setColor( Color.WHITE);
           canvas.drawPaint( paint );
           paint.setColor( Color.RED );
           canvas.drawCircle( x/2,y/2,radious,paint );



setContentView(new MyView(this) ):Here we have to pass the object of my own create class MyView.

MediaController mediaController:This statement declare the object mediaController of MediaController .

public class MyView extends View:Here i have created my class MyView and extends the View class.

public MyView(Context context):Here i have created the constructor of MyView class.

super(context):Here i have called the constructor of Viw class with in constructor of MyView class.

protected void onDraw(Canvas canvas):Here i have override the onDraw().

super.onDraw(canvas):Here i have called the onDraw() of super class and pass the canvas object as argument.

Paint paint=new Paint():Here i have created the object paint of the Paint class.


int x=getWidth():The getWidth() return the width of current view and this width i have assigned into the variable x.

int y=getHeight():The getWidth() return the height of current view and this height i have assigned into the variable y.

int radious=100:This statement assigned the 100 value to radious variable.

paint.setStyle( Paint.Style.FILL );:The setStyle() set the style to fill the view with color.

paint.setColor( Color.WHITE):The setColor() set the color of view.

canvas.drawPaint( paint ):Fill the entire canvas bitmap (restricted to the current clip) with the specified paint..

paint.setColor( Color.RED ):Set the color of drawn shape in my case it is red color for circle.

canvas.drawCircle( x/2,y/2,radious,paint ):drawCircle() simple draw the circle it will take four argument first is x coordinat that is half width of the view and second is y coordinate that is half height of the view and third is radius that is 100 the last argument is paint.


what is graphics circle for video click here

back image                     back image