Android application to display "Home Screen", press button shape to display shapes
b) Write an Android application to display “Home Screen”, press button shape to display shapes (Circle Square and Triangle). On the “Shape” screen press “HOME” to go back to home screen using Intents. [10]
Ans. Create a new project by File-> New -> Android Project
I have written here the main logic of creating the different shape in java file, the rest you can do by using Intents.
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(new MyView(this));
}
public class MyView extends View
{
public MyView(Context context)
{
super(context);
}
@Override
protected void onDraw(Canvas canvas)
{
// TODO Auto-generated method stub
super.onDraw(canvas);
int x = getWidth();
int y = getHeight();
int radius=50;
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
canvas.drawPaint(paint);
paint.setColor(Color.CYAN);
canvas.drawCircle(x / 2, y / 2, radius, paint);
canvas.drawRect(50, 50, 100, 100, paint);
}
}
}