0% found this document useful (0 votes)
42 views

Primitives: Mainactivity - XML

This document contains code for a simple Android application that draws a green circle on the screen. It includes an XML layout file for the main activity containing a RelativeLayout. The MainActivity Java file extends ActionBarActivity and sets the content view to a custom View class that overrides the onDraw method. This onDraw method creates a Paint object, sets the color to green, and draws a circle of radius 50 pixels at the coordinates (200, 200) on the Canvas.

Uploaded by

Ganesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Primitives: Mainactivity - XML

This document contains code for a simple Android application that draws a green circle on the screen. It includes an XML layout file for the main activity containing a RelativeLayout. The MainActivity Java file extends ActionBarActivity and sets the content view to a custom View class that overrides the onDraw method. This onDraw method creates a Paint object, sets the color to green, and draws a circle of radius 50 pixels at the coordinates (200, 200) on the Canvas.

Uploaded by

Ganesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Primitives:

MainActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="examp.surya2.prim.MainActivity">

</RelativeLayout>

MainActivity.java
package examp.surya2.prim;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(new myview(this));
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private class myview extends View
{
public myview(Context context){
super(context);
}
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
Paint paint=new Paint();
paint.setColor(Color.GREEN);
canvas.drawCircle(200,200,50,paint);
}

}
}

output

You might also like