0% found this document useful (0 votes)
7 views6 pages

Android Ex1, Practical

The document outlines the procedure for developing a simple Android application that utilizes GUI components, fonts, and colors. It includes steps for creating a new project, designing the layout in XML, and coding the main activity in Java. The application allows users to change the font size and color of a text view through button interactions, and it successfully demonstrates the use of these features.

Uploaded by

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

Android Ex1, Practical

The document outlines the procedure for developing a simple Android application that utilizes GUI components, fonts, and colors. It includes steps for creating a new project, designing the layout in XML, and coding the main activity in Java. The application allows users to change the font size and color of a text view through button interactions, and it successfully demonstrates the use of these features.

Uploaded by

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

Android Application that uses GUI components, Font and

Colors
BY DEVANG · FEBRUARY 27, 2016

Aim:
To develop a Simple Android Application that uses GUI components, Font and
Colors.

Procedure:
Creating a New project:
▪ Open Android Stdio and then click on File -> New -> New project.

▪ Then type the Application name as “ex.no.1″ and click Next.


▪ Then select the Minimum SDK as shown below and click Next.
▪ Then select the Empty Activity and click Next.
▪ Finally click Finish.
▪ It will take some time to build and load the project.
▪ After completion it will look as given below.
Designing layout for the Android Application:
▪ Click on app -> res -> layout -> activity_main.xml.
▪ Now click on Text as shown below.
▪ Then delete the code which is there and type the code as given below.
Code for Activity_main.xml:
?
<?xml version="1.0" encoding="utf-8"?>
1
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2
android:orientation="vertical"

3
android:layout_width="match_parent"

4 android:layout_height="match_parent">

6 <TextView

android:id="@+id/textView"
7
android:layout_width="match_parent"
8
android:layout_height="wrap_content"

9
android:layout_margin="30dp"

10 android:gravity="center"

11 android:text="Hello World!"

android:textSize="25sp"
12
android:textStyle="bold" />
13

14
<Button

15
android:id="@+id/button1"

16 android:layout_width="match_parent"

17 android:layout_height="wrap_content"

android:layout_margin="20dp"
18
android:gravity="center"
19
android:text="Change font size"

20
android:textSize="25sp" />

21 <Button
android:id="@+id/button2"
22

android:layout_width="match_parent"
23
android:layout_height="wrap_content"

24
android:layout_margin="20dp"

25
android:gravity="center"

26 android:text="Change color"

android:textSize="25sp" />
27

</LinearLayout>
28

29

30

31

32

33

▪ Now click on Design and your application will look as given below.
▪ So now the designing part is completed.
Java Coding for the Android Application:
▪ Click on app -> java -> com.example.exno1 -> MainActivity.
▪ Then delete the code which is there and type the code as given below.
Code for MainActivity.java:
?
package com.example.exno1;
1

2
import android.graphics.Color;

3
import android.support.v7.app.AppCompatActivity;

4
import android.os.Bundle;
import android.view.View;
5

import android.widget.Button;
6
import android.widget.TextView;

8
public class MainActivity extends AppCompatActivity

9
{

10 int ch=1;

float font=30;
11

@Override
12
protected void onCreate(Bundle savedInstanceState)

13
{

14
super.onCreate(savedInstanceState);

15 setContentView(R.layout.activity_main);

final TextView t= (TextView) findViewById(R.id.textView);


16

Button b1= (Button) findViewById(R.id.button1);


17
b1.setOnClickListener(new View.OnClickListener() {

18
@Override

19
public void onClick(View v) {

20 t.setTextSize(font);

font = font + 5;
21

if (font == 50)
22
font = 30;

23
}

24
});

25 Button b2= (Button) findViewById(R.id.button2);


b2.setOnClickListener(new View.OnClickListener() {
26

@Override
27
public void onClick(View v) {

28
switch (ch) {

29
case 1:

30 t.setTextColor(Color.RED);

break;
31

case 2:
32
t.setTextColor(Color.GREEN);

33
break;

34
case 3:

35 t.setTextColor(Color.BLUE);

break;
36

case 4:
37
t.setTextColor(Color.CYAN);

38
break;

39
case 5:

40 t.setTextColor(Color.YELLOW);

break;
41

case 6:
42
t.setTextColor(Color.MAGENTA);

43
break;

44
}

45 ch++;

if (ch == 7)
46
ch = 1;
47

}
48
});

49
}

50
}

51

52

53

54

55

56

57

58

59

60

▪ So now the Coding part is also completed.


▪ Now run the application to see the output.
Output:

Result:
Thus a Simple Android Application that uses GUI components, Font and Colors
is developed and executed successfully.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy