Android File
Android File
<TextView
android:id="@+id/textView"
android:layout_width="406dp"
android:layout_height="61dp"
android:fontFamily="sans-serif-black"
android:text=" Hello Android!!"
android:textAlignment="center"
android:textColor="#878383"
android:textSize="34sp"
tools:layout_editor_absoluteX="3dp"
tools:layout_editor_absoluteY="293dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Program 2
AIM: To make a login page
CODE: XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="100dp"
app:srcCompat="@drawable/screenshot__16_" />
<EditText
android:id="@+id/editTextTextEmailAddress"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="50dp"
android:ems="10"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/editTextTextPassword"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="30dp"
android:ems="10"
android:inputType="textPassword" />
<TextView
android:id="@+id/textView"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="40dp"
android:fontFamily="sans-serif-medium"
android:text="No. of attempts left "
android:textAlignment="center"
android:textSize="16sp" />
<Button
android:id="@+id/button"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginLeft="130dp"
android:layout_marginTop="50dp"
android:text="Login" />
</LinearLayout>
STEPS: -
Program 3
AIM: To try 4 views of android studio
CODE: XML
1) Linear layout (vertical)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="279dp"
app:srcCompat="@drawable/helianthus_yellow_flower_pixabay_11863" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="91dp"
android:layout_marginLeft="50dp"
android:fontFamily="sans-serif-medium"
android:text="Sunflowers"
android:textSize="60sp" />
</LinearLayout>
2) Linear layout (Horizontal)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="279dp"
app:srcCompat="@drawable/helianthus_yellow_flower_pixabay_11863" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="91dp"
android:layout_marginLeft="50dp"
android:fontFamily="sans-serif-medium"
android:text="Sunflowers"
android:textSize="60sp" />
</LinearLayout>
3) Relative layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="279dp"
app:srcCompat="@drawable/helianthus_yellow_flower_pixabay_11863" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="91dp"
android:layout_marginLeft="50dp"
android:fontFamily="sans-serif-medium"
android:text="Sunflowers"
android:textSize="60sp" />
</Relative layout>
4) Grid layout: -
<?xml version="1.0" encoding="utf-8"?>
<GridLayout 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:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="215dp"
android:layout_height="148dp"
app:srcCompat="@drawable/helianthus_yellow_flower_pixabay_11863" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="91dp"
android:fontFamily="sans-serif-medium"
android:text="Sunflowers"
android:textSize="34sp" />
</GridLayout>
Program 4
AIM: To make a portfolio.
CODE: XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:orientation="vertical"
android:textAlignment="center"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:fontFamily="sans-serif-black"
android:text="PORTFOLIO"
android:textAlignment="center"
android:textColor="#454141"
android:textSize="60sp" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="309dp"
android:layout_marginTop="20dp"
android:textAlignment="center"
app:srcCompat="@drawable/its_me" />
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Name:- Shivangi Mishra "
android:textAlignment="center"
android:textColor="#EFE8E8"
android:textSize="24sp" />
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Age:- 21 "
android:textAlignment="center"
android:textColor="#EFE8E8"
android:textSize="24sp" />
</Linear layout>
Program 5
AIM: To add a toast message to login page.
CODE: XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#030B3A"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
app:srcCompat="@drawable/screenshot__16_" />
<EditText
android:id="@+id/editTextTextEmailAddress"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="50dp"
android:ems="10"
android:hint="username"
android:inputType="textEmailAddress"
android:textColor="#FFFFFF"
android:textColorHint="#FFFFFF" />
<EditText
android:id="@+id/editTextTextPassword"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="30dp"
android:ems="10"
android:hint="password"
android:inputType="textPassword"
android:textColor="#FFFFFF"
android:textColorHint="#FFFFFF" />
<TextView
android:id="@+id/textView"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="40dp"
android:fontFamily="sans-serif-medium"
android:text="No. of attempts left 5"
android:textAlignment="center"
android:textColor="#FFF9F9"
android:textSize="16sp" />
<Button
android:id="@+id/button"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginLeft="130dp"
android:layout_marginTop="50dp"
android:text="Login" />
</LinearLayout>
XML (secondActivity)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#030B3A"
tools:context=".SecondActivity">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="350dp"
android:layout_weight="8"
android:fontFamily="sans-serif-black"
android:text="Welcome here !!"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="34sp"
android:textStyle="bold|italic" />
</LinearLayout>
JAVA
package com.example.shivangiloginpage;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Name = (EditText)findViewById(R.id.editTextTextEmailAddress);
Password = (EditText)findViewById(R.id.editTextTextPassword);
Info = (TextView)findViewById(R.id.textView);
Login = (Button)findViewById(R.id.button);
}
private void validate(String userName, String userPassword){
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#BD7C1B"
android:fontFamily="sans-serif"
android:text="Mobile app development is the act or process by which a mobile app is
developed for mobile devices, such as personal digital assistants, enterprise digital assistants
or mobile phones. These software applications are designed to run on mobile devices, such as
a smartphone or tablet computer. These applications can be pre-installed on phones during
manufacturing platforms, or delivered as web applications using server-side or client-side
processing (e.g., JavaScript) to provide an "application-like" experience within a
web browser. Application software developers also must consider a long array of screen
sizes, hardware specifications, and configurations because of intense competition in mobile
software and changes within each of the platforms. Mobile app development has been
steadily growing, in revenues and jobs created. A 2013 analyst report estimates there are
529,000 direct app economy jobs within the EU then 28 members (including the UK), 60
percent of which are mobile app developers.[1] As part of the development process, mobile
user interface (UI) design is also essential in the creation of mobile apps. Mobile UI considers
constraints, contexts, screen, input, and mobility as outlines for design. The user is often the
focus of interaction with their device, and the interface entails components of both hardware
and software. User input allows for the users to manipulate a system, and device's output
allows the system to indicate the effects of the users' manipulation. Mobile UI design
constraints include limited attention and form factors, such as a mobile device's screen size
for a user's hand(s). Mobile UI contexts signal cues from user activity, such as location and
scheduling that can be shown from user interactions within a mobile app. Overall, mobile UI
design's goal is mainly for an understandable, user-friendly interface. Functionality is
supported by mobile enterprise application platforms or integrated development
environments (IDEs). Mobile UIs, or front-ends, rely on mobile back-ends to support access
to enterprise systems. The mobile back-end facilitates data routing, security, authentication,
authorization, working off-line, and service orchestration. This functionality is supported by a
mix of middleware components including mobile app server, mobile backend as a service
(MBaaS), and service-oriented architecture (SOA) infrastructure."
android:textAlignment="viewStart"
android:textColor="#101010"
android:textSize="34sp" />
</ScrollView>
STEPS
Program 7
AIM: To Design an application to show justification of text.
CODE: XML
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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/alingment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#05013A"
android:textAlignment="center"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="Aim:- TO JUSTIFY TEXT"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="IT IS ABOUT ANDROID STUDIO APP"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<me.biubiubiu.justifytext.library.JustifyTextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Android Studio is the official integrated development environment
(IDE) for Android application development. It is based on IntelliJ IDEA, a Java integrated
development environment for software, and incorporates its code editing and developer
tools."
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<me.biubiubiu.justifytext.library.JustifyTextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="To support application development within the Android operating
system, Android Studio uses a Gradle-based build system, Android Emulator, code templates
and GitHub integration. Every project in Android Studio has one or more modalities with
source code and resource files. These modalities include Android app modules, Library
modules and Google App Engine modules.Android Studio uses an Apply Changes feature to
push code"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<me.biubiubiu.justifytext.library.JustifyTextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" and resource changes to a running application. A code editor assists the
developer with writing code and offering code completion, refraction and analysis.
Applications built in Android Studio are then compiled into the APK format for submission
to the Google Play Store.The software was first announced at Google I/O in May 2013,and
the first stable build was released in December 2014. Android Studio is available for macOS,
Windows and Linux desktop platforms. It replaced Eclipse Android Development Tools
(ADT) as the primary IDE for Android application development. Android Studio and the
Software Development Kit can be downloaded directly from Google."
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<me.biubiubiu.justifytext.library.JustifyTextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" and the first stable build was released in December 2014. Android
Studio is available for macOS, Windows and Linux desktop platforms. It replaced Eclipse
Android Development Tools (ADT) as the primary IDE for Android application
development. Android Studio and the Software Development Kit can be downloaded directly
from Google."
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<me.biubiubiu.justifytext.library.JustifyTextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Android Studio was announced on 16th May 2013 at the Google I/O
conference as an official IDE for Android app development. It started its early access preview
from version 0.1 in May 2013. The first stable built version was released in December 2014,
starts from version 1.0.By default, Android Studio displays our project files in the Android
project view, as shown in the above image. This view is formed by modules to provide quick
access to our project's key source files."
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<me.biubiubiu.justifytext.library.JustifyTextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="By default, Android Studio displays our project files in the Android
project view, as shown in the above image. This view is formed by modules to provide quick
access to our project's key source files."
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</LinearLayout>
</ScrollView>
STEPS
Program 8
AIM: Use of Scroll View in your application in the following ways With a
Linear Layout having consisting of multiple views.
CODE: XML
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#EA6732"
android:fillViewport="true"
android:padding="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:fontFamily="sans-serif"
android:text="Places to visit in Delhi"
android:textAlignment="center"
android:textColor="#045A9F"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:fontFamily="sans-serif"
android:text="1. The Red Fort"
android:textColor="#000000"
android:textSize="25sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="match_parent"
android:layout_height="258dp"
android:layout_marginTop="10dp"
app:srcCompat="@drawable/redfortt" />
<me.biubiubiu.justifytext.library.JustifyTextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:fontFamily="sans-serif"
android:text="The beautiful Red Fort was built by Shah Jahan in1648 and served
as the seat of Mughal power until 1857. This stunning structure, with its tall, red
sandstone walls covers an area of more than two square kilometers, the entirety of which
is crescent shaped and surrounded by a moat. The impressive main entrance, the Lahore
Gate, is so named as it faces towards Lahore in Pakistan, while the even grander Delhi
Gate was used by the emperor for ceremonial processions."
android:textColor="#A0D0F6"
android:textSize="20sp"
android:textAlignment="center"/>
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:fontFamily="sans-serif"
android:text="2. Qutub Minar"
android:textColor="#000000"
android:textSize="25sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="274dp"
android:layout_marginTop="10dp"
app:srcCompat="@drawable/qm" />
<me.biubiubiu.justifytext.library.JustifyTextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:fontFamily="sans-serif"
android:text="Completed in the 12th century, the beautiful Qutub Minar-India's
tallest minaret and now a UNESCO Word Heritage Site-attracts many international
visitors eager to climb to the top for its breathtaking views of the surrounding area. This
ornate five-story tower rises more than 70 meters and is covered"
android:textColor="#A0D0F6"
android:textSize="20sp"
android:textAlignment="center"/>
<me.biubiubiu.justifytext.library.JustifyTextView
android:id="@+id/textView8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" with intricate carvings featuring the history of Qutub along with
inscriptions from the Koran. It's also notable for being constructed of a number of
different types of stone (the first three stories are made of red sandstone, while the fourth
and fifth stories were built with marble and sandstone).. In general, minarets were slow to
be used in India and are often detached from the main mosque where they exist.'The
Qutb Minar has a shaft that is fluted with superb stalactite bracketing under the balconies
at the top of each"
android:fontFamily="sans-serif"
android:textColor="#A0D0F6"
android:textSize="20sp"
android:textAlignment="center"/>
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:fontFamily="sans-serif"
android:text="3. Lotus Temple"
android:textColor="#000000"
android:textSize="25sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="268dp"
android:layout_marginTop="10dp"
app:srcCompat="@drawable/lt" />
<me.biubiubiu.justifytext.library.JustifyTextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:fontFamily="sans-serif"
android:text="The Lotus Temple, located in Delhi, India, is a Baháʼí House of
Worship that was dedicated in December 1986. Notable for its lotus like shape, it has
become a prominent attraction in the city. Like all Bahá’í Houses of Worship, the Lotus
Temple is open to all, regardless of religion or any other qualification. The building is
composed of 27 free-standing marble-clad "petals" arranged in clusters of
three to form nine sides,with nine doors opening onto a central hall with a height of
slightly over 34 meters[1] and a capacity of 1,300 people million.The major"
android:textColor="#A0D0F6"
android:textSize="20sp"
android:textAlignment="center"/>
<me.biubiubiu.justifytext.library.JustifyTextView
android:id="@+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:textColor="#A0D0F6"
android:textSize="20sp"
android:textAlignment="center"
android:text="part of the funds needed to buy this land was donated by Ardishír
Rustampúr of Hyderabad, Sindh (Pakistan), whose will dictated that his entire life
savings would go to this purpose.[12][page needed] A portion of the construction budget
was saved and used to build a greenhouse to study indigenous plants and flowers that
would be appropriate for use on the site."" />
</LinearLayout>
</ScrollView>
STEPS
Program 9
AIM: Use Horizonal Scroll View for multiple images.
CODE: XML
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF5722"
android:backgroundTintMode="src_over"
android:fillViewport="true"
android:padding="16dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#FF5722"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView"
android:layout_width="315dp"
android:layout_height="211dp"
android:layout_weight="1"
app:srcCompat="@drawable/qm" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="280dp"
android:layout_height="213dp"
android:layout_weight="1"
app:srcCompat="@drawable/red_fort" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:srcCompat="@drawable/lt" />
</LinearLayout>
</HorizontalScrollView>
Program 10
AIM: To make activity lice cycle
CODE: XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4F65ED"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="300dp"
android:fontFamily="sans-serif-black"
android:text="Activity Life Cycle !!"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
JAVA
package com.example.activitylifecycle;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
super.onStart();
@Override
super.onResume();
@Override
super.onPause();
@Override
protected void onStop() {
super.onStop();
@Override
super.onDestroy();
}
}
STEPS
Program 11
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="267dp"
android:layout_weight="1"
app:srcCompat="@drawable/wf" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="462dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20sp"
android:layout_marginTop="5dp"
android:background="@drawable/textview_bg"
android:text="William Faulkner"
android:textAlignment="center"
android:textSize="32sp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:text="@string/truthquote"
android:textAlignment="center"
android:textColor="@color/green"
android:textSize="32sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:layout_marginRight="20dp"
android:text="@string/quote"
android:textColor="@color/white"
android:textSize="24sp"
android:textStyle="bold" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:layout_marginRight="20dp"
android:backgroundTint="@color/green"
android:drawableRight="?attr/actionModeShareDrawable"
android:drawableTint="#fff"
android:text="SHARE OPTION"
android:textAlignment="textStart"
android:textSize="20sp"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
JAVA
package com.example.implicitintent;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
Button share;
TextView quote;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
share = findViewById(R.id.button);
quote = findViewById(R.id.textView3);
share.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
String sharetxt = quote.getText().toString();
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT , sharetxt);
startActivity(sendIntent);
}
});
}
Strings.Xml
<resources>
<string name="app_name">Implicit Intent</string>
Colours.Xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="green">#38b750</color>
</resources>
TextView_bg
STEPS
0
Program 12
AIM: To create a menu bar
CODE: XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E3B119"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="300dp"
android:fontFamily="sans-serif"
android:text="Aim :- To Make Menu Bar"
android:textAlignment="center"
android:textColor="#1731DF"
android:textSize="30sp"
android:textStyle="bold"
tools:layout_editor_absoluteX="53dp"
tools:layout_editor_absoluteY="234dp" />
</LinearLayout>
JAVA
package com.example.menubar;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflator =getMenuInflater();
inflator.inflate(R.menu.option_menu,menu);
return true;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch(item.getItemId()) {
case R.id.status1:
Toast.makeText(this, "Status Selected.", Toast.LENGTH_SHORT).show();
case R.id.settings1:
Toast.makeText(this, "Settings Selected.", Toast.LENGTH_SHORT).show();
case R.id.account:
Toast.makeText(this, "Account Selected.", Toast.LENGTH_SHORT).show();
case R.id.chats:
Toast.makeText(this, "Chats Selected.", Toast.LENGTH_SHORT).show();
case R.id.notifications:
Toast.makeText(this, "Notifications Selected.", Toast.LENGTH_SHORT).show();
case R.id.storage:
Toast.makeText(this, "Storage and Data Selected.",
Toast.LENGTH_SHORT).show();
case R.id.help:
Toast.makeText(this, "Help Selected.", Toast.LENGTH_SHORT).show();
case R.id.logout1:
Toast.makeText(this, "Logout Selected.", Toast.LENGTH_SHORT).show();
default:
return super.onOptionsItemSelected(item);
}
}
}
Option_Menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:title="Status"
android:id="@+id/status1"/>
<item
android:title="Settings"
android:id="@+id/settings1"
app:showAsAction="never">
<menu>
<item
android:title="Account"
android:id="@+id/account"/>
<item
android:title="Chats"
android:id="@+id/chats"/>
<item
android:title="Notifications"
android:id="@+id/notifications"/>
<item
android:title="Storage and Data"
android:id="@+id/storage"/>
<item
android:title="Help"
android:id="@+id/help"/>
</menu>
</item>
<item
android:title="Logout"
android:id="@+id/logout1"/>
</menu>
STEPS
Program 13
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="serif"
android:gravity="center_horizontal"
android:text="CALCULATOR"
android:textSize="40sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:inputType="number"
android:ems="10"
android:id="@+id/editText1"
android:textSize="18sp"
android:gravity="center_horizontal"
android:layout_marginBottom="5dp" />
JAVA
package com.example.calculator;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText1 = findViewById(R.id.editText1);
editText2 = findViewById(R.id.editText2);
buttonAdd = findViewById(R.id.buttonAdd);
buttonSubtract = findViewById(R.id.buttonSubtract);
buttonMultiply = findViewById(R.id.buttonMultiply);
buttonDivide = findViewById(R.id.buttonDivide);
buttonClear = findViewById(R.id.buttonClear);
textViewResult = findViewById(R.id.textViewResult);
buttonAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int num1 = Integer.parseInt(editText1.getText().toString());
int num2 = Integer.parseInt(editText2.getText().toString());
int result = num1 + num2;
textViewResult.setText("Result: " + result);
}
});
buttonSubtract.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int num1 = Integer.parseInt(editText1.getText().toString());
int num2 = Integer.parseInt(editText2.getText().toString());
int result = num1 - num2;
textViewResult.setText("Result: " + result);
}
});
buttonMultiply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int num1 = Integer.parseInt(editText1.getText().toString());
int num2 = Integer.parseInt(editText2.getText().toString());
int result = num1 * num2;
textViewResult.setText("Result: " + result);
}
});
buttonDivide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int num1 = Integer.parseInt(editText1.getText().toString());
int num2 = Integer.parseInt(editText2.getText().toString());
if (num2 == 0) {
textViewResult.setText("Result: Infinity");
} else {
float result = (float) num1 / (float) num2;
textViewResult.setText("Result: " + result);
}
}
});
buttonClear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
editText1.setText("");
editText2.setText("");
textViewResult.setText("Result: ");
}
});
}
}
STEPS
Program 14
AIM: To Design and create an android app to add location using google maps.
CODE:
MAPS_API_KEY=AIzaSyBew9nd1IDeMElViCa0fsh-ENzyo6TRxQg
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.GoogleMap"
tools:targetApi="31">
<!--
TODO: Before you run your application, you need a Google Maps API key.
https://developers.google.com/maps/documentation/android-sdk/get-api-key
Once you have your API key (it starts with "AIza"), define a new property in your
project's local.properties file (e.g. MAPS_API_KEY=Aiza...), and replace the
"YOUR_API_KEY" string in this file with "${MAPS_API_KEY}".
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${MAPS_API_KEY}" />
<activity
android:name=".MapsActivity"
android:exported="true"
android:label="@string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
STEPS
Program 15
AIM: To Create and Add Data to SQLite Database in Android
CODE: XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/idEdtCourseName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginTop="50dp"
android:hint="Enter course Name" />
<EditText
android:id="@+id/idEdtCourseDuration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Enter Course Duration" />
<EditText
android:id="@+id/idEdtCourseTracks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Enter Course Tracks" />
<EditText
android:id="@+id/idEdtCourseDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Enter Course Description" />
<Button
android:id="@+id/idBtnAddCourse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Add Course"
android:textAllCaps="false" />
</LinearLayout>
JAVA
package com.example.database;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
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);
courseNameEdt = findViewById(R.id.idEdtCourseName);
courseTracksEdt = findViewById(R.id.idEdtCourseTracks);
courseDurationEdt = findViewById(R.id.idEdtCourseDuration);
courseDescriptionEdt = findViewById(R.id.idEdtCourseDescription);
addCourseBtn = findViewById(R.id.idBtnAddCourse);
addCourseBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DBHandler
package com.example.database;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DBHandler extends SQLiteOpenHelper {
db.execSQL(query);
}
db.close();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// this method is called to check if the table exists already.
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
STEPS
Program 16
AIM: To Create List View in an Android App
CODE: XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
JAVA
package com.example.listview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
ListView listview;
String tutorials[]
= {"Algorithms", "Data Structures",
"Languages", "Maths",
"GATE", "Computers",
"UGC NET CS", "CS Subjects",
"Web Technologies"};
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview = findViewById(R.id.list);
ArrayAdapter<String> arr = new ArrayAdapter<String>(
this,
androidx.appcompat.R.layout.support_simple_spinner_dropdown_item,
tutorials);
listview.setAdapter(arr);
}
}
STEPS
Program 17
AIM: To Create an App to Open a Camera through Intent and Display
Captured Image.
CODE: XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id= "@+id/click_image"
android:layout_width="350dp"
android:layout_height="450dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="70dp"
android:layout_marginBottom="10dp"/>
<Button
android:id="@+id/button"
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_marginLeft="60dp"
android:layout_marginTop="600dp"
android:layout_marginBottom="30dp"
android:text="Camera" />
</RelativeLayout>
JAVA
package com.example.camera;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.widget.Button;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// By ID we can get each component which id is assigned in XML file get Buttons and
imageview.
camera_open_id = findViewById(R.id.button);
click_image_id = findViewById(R.id.click_image);
// Camera_open button is for open the camera and add the setOnClickListener in this
button
camera_open_id.setOnClickListener(v -> {
// Create the camera_intent ACTION_IMAGE_CAPTURE it will open the camera for
capture the image
Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Start the activity with camera_intent, and request pic id
startActivityForResult(camera_intent, pic_id);
});
}