Professional Documents
Culture Documents
Android Term
Android Term
rectangle and square. Fill all these primitives with different colours.
OBJECTIVE: To learn the concept of relative layout and imageview
XML SOURCECODE:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView" />
</RelativeLayout>
JAVA SOURCECODE:-
package com.example.myapplication;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.ImageView;
import com.example.myapplication.R;
//Creating a Bitmap
Bitmap bg = Bitmap.createBitmap(720, 1280, Bitmap.Config.ARGB_8888);
//Creating the Paint Object and set its color & TextSize
Paint paint = new Paint();
paint.setColor(Color.RED);
paint.setTextSize(50);
OUTPUT:-
PROBLEM STATEMENT 4: Create an application which displays three buttons named Red,
Yellow, and Green. The background colour of activity should be changed to appropriate
colour when user click on any of these buttons.
OBJECTIVE:- To learn the concept of button and setbackground method
XML SOURCECODE:-
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/lay"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RED"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.146" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GREEN"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/button"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/button"
app:layout_constraintTop_toBottomOf="@+id/button"
app:layout_constraintVertical_bias="0.252" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YELLOW"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/button2"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="@+id/button2"
app:layout_constraintTop_toBottomOf="@+id/button2"
app:layout_constraintVertical_bias="0.335" />
</androidx.constraintlayout.widget.ConstraintLayout>
JAVA SOURCECODE:-
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b1,b2,b3;
TextView t1;
ConstraintLayout lay;
b1=findViewById(R.id.button);
b2=findViewById(R.id.button2);
lay=findViewById(R.id.lay);
b3=findViewById(R.id.button3);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
lay.setBackgroundColor(Color.RED);
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
lay.setBackgroundColor(Color.GREEN);
}
});
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
lay.setBackgroundColor(Color.YELLOW);
}
});
}
}
OUTPUT:-
PROBLEM STATEMENT 3: Write an Android code to show the working of Activity Lifecycle
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
JAVA SOURCECODE:-
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("activity_lifecycle","Oncreate_invoked");
}
protected void onRestart(){
super.onRestart();
Log.d("activity_lifecycle","OnRestart_invoked");
}
protected void onStart(){
super.onStart();
Log.d("activity_lifecycle","OnStart_invoked");
}
protected void onResume(){
super.onResume();
Log.d("activity_lifecycle","OnResume_invoked");
}
protected void onPause(){
super.onPause();
Log.d("activity_lifecycle","OnPause_invoked");
}
protected void onStop(){
super.onStop();
Log.d("activity_lifecycle","OnStop_invoked");
}
protected void onDestroy(){
super.onDestroy();
Log.d("activity_lifecycle","OnDestroy_invoked");
}
}
OUTPUT:-
PROBLEM STATEMENT 6: Develop an application that validates the login page and
registration page.
OBJECTIVE:- To learn the objective of toast and if statement
XML SOURCECODE:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/usernameEditText"
android:hint="Username"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/passwordEditText"
android:hint="Password"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:text="Login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="login" />
</LinearLayout>
JAVA SOURCECODE:-
package com.example.myapplication;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
usernameEditText = findViewById(R.id.usernameEditText);
passwordEditText = findViewById(R.id.passwordEditText);
}
OUTPUT:-
PROBLEM STATEMENT 7: Write an Android code to design a password with the combination of
letter, digit and special character.
OBJECTIVE:- To learn the concept of String and android programing
XML SOURCECODE:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:id="@+id/passwordTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:textStyle="bold" />
<Button
android:id="@+id/generatePasswordButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Generate Password"
android:onClick="generatePasswordButtonOnClick"
android:layout_marginTop="24dp" />
</LinearLayout>
JAVA SOURCECODE:-
package com.example.passwordgenrate;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.example.passwordgenrate.R;
import java.util.Random;
TextView passwordTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
passwordTextView = findViewById(R.id.passwordTextView);
OUTPUT: