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 rectangle at the screen with red color.Pls see the image.


In this section i am going to show the graphics rectangle 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();
           paint.setStyle( Paint.Style.FILL );
           paint.setColor( Color.WHITE);
           canvas.drawPaint( paint );
           paint.setColor( Color.RED );
           canvas.drawRect( 200,200,500,100 ,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.


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 rectangle.

canvas.drawRect( 200,200,500,100 ,paint):drawRect() simple draw the rectangle.

Graphics Rectangle

what is video rectangle for video click here

back image                     back image