Here I give full source code in Java and XMl, Sample output with mobile application in .apk format.

EX.NO 1      Develop an application that uses GUI components, Font and Colours

Aim:

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

Procedure:

Creating a New project:

  • First open the Android studio tool.
  • Then click on File -> New -> New project.
  • Then select a Project Template
  • Then configure your project, Select the language and Minimum SDK, I recommend use Oreo or Pie Android version.
  • Finally click Finish.
  • Successfully create your project, Its Java file.
  • Its designing part click on split button , Open the XML file.

Program:

XML code:

activity_main.xml:

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout android:layout_height=”match_parent” android:layout_width=”match_parent”
android:orientation=”vertical”
xmlns:android=”http://schemas.android.com/apk/res/android”>
<TextView
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:id=”@+id/tv1″
android:text=”Hello World”
android:gravity=”center”
android:textStyle=”bold”
android:textSize=”25sp”
android:layout_margin=”30dp”
/>
<Button
android:id=”@+id/button1″
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_margin=”20dp”
android:gravity=”center”
android:text=”Change font size”
android:textSize=”25sp” android:backgroundTint=”@color/black”/>

<Button
android:id=”@+id/button2″
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_margin=”20dp”
android:gravity=”center”
android:text=”Change color”
android:textSize=”25sp”
android:backgroundTint=”@color/black”
/>
<TextView
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”Mobile Application Development Laboratory”
android:textColor=”#0000FF”
android:gravity=”center”
android:textStyle=”bold”
android:textSize=”25sp”
android:layout_margin=”30dp”
/>

</LinearLayout>

  • 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.expriment1 -> MainActivity.java

Java code:

package com.example.expriment1;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
int ch=1;
float font=30;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView t1 = (TextView) findViewById(R.id.tv1);
Button b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
t1.setTextSize(font);
font = font+5;
if (font==50)
{
font=30;
}
}
});
Button b2 = (Button) findViewById(R.id.button2);
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (ch) {
case 1:
t1.setTextColor(Color.RED);
break;
case 2:
t1.setTextColor(Color.GREEN);
break;
case 3:
t1.setTextColor(Color.BLUE);
break;
case 4:
t1.setTextColor(Color.CYAN);
break;
case 5:
t1.setTextColor(Color.YELLOW);
break;
case 6:
t1.setTextColor(Color.MAGENTA);
break;
}
ch++;
if (ch == 7) {
ch = 1;
}
}
});
}
}

  • 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.

Here I was attach my Mobile Application in .apk format.

Click on blow link: (Download the mobile app)

https://drive.google.com/file/d/1IOk12PnF2FlrYtw_aYYnEfFjW_XLEPIe/view?usp=sharing

Any quires leave a comment , I will Try to answer soon.

Leave a Reply

Your email address will not be published. Required fields are marked *