Android Application that uses GUI components, Font and Colors

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.

new project

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

application name

  • Then select the Minimum SDK as shown below and click Next.

minimum sdk

  • Then select the Empty Activity and click Next. 

empty activity

  • Finally click Finish.

finish

  • It will take some time to build and load the project.
  • After completion it will look as given below.

new

Designing layout for the Android Application:

  • Click on app -> res -> layout -> activity_main.xml.

activity_main

  • Now click on Text as shown below.

text

  • 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"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="30dp"
        android:gravity="center"
        android:text="Hello World!"
        android:textSize="25sp"
        android:textStyle="bold" />

    <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" />
    <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" />
</LinearLayout>
  • Now click on Design and your application will look as given below.

design

  • So now the designing part is completed.

Java Coding for the Android Application:

  • Click on app -> java -> com.example.exno1 -> MainActivity.

MainActivity

  • Then delete the code which is there and type the code as given below.

Code for MainActivity.java:

package com.example.exno1;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
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 t= (TextView) findViewById(R.id.textView);
        Button b1= (Button) findViewById(R.id.button1);
        b1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                t.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:
                        t.setTextColor(Color.RED);
                        break;
                    case 2:
                        t.setTextColor(Color.GREEN);
                        break;
                    case 3:
                        t.setTextColor(Color.BLUE);
                        break;
                    case 4:
                        t.setTextColor(Color.CYAN);
                        break;
                    case 5:
                        t.setTextColor(Color.YELLOW);
                        break;
                    case 6:
                        t.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:

ex1-s1        ex1-s2        ex1-s7

ex1-s5        ex1-s4        ex1-s3

Result:

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

 

You may also like...

19 Responses

  1. amar durai says:

    its very good devolpmemt application…..tq for this…

  2. janagalakshmi says:

    its very good devolpmemt application…..tq for this…

  3. sravanthi says:

    chala claritygaa undi sir

  4. kannan says:

    its very good development application…….tq for this …….

  5. kirthi says:

    good development

  6. sivamani says:

    i love u coding…

  7. kumaresa Mani says:

    i have intrested java,PHP,PHYTON
    any way thank u for the gudlines

  8. Santhiya says:

    Nandriii

  9. kowshika says:

    nice

  10. jeevanandham says:

    good development guys…..

  11. hi thanks for the coding ….

  12. Giridharan Mec says:

    super nice coding sir vera lvl…………..

  13. Abinaya R says:

    good coding

  14. vinay says:

    nice and easlily understand

  15. adarsh says:

    wow its good

  16. prasanth says:

    very nice

  17. vishwajit singh says:

    very helpful for our sem.. exam thanks….

  18. joe praqkash says:

    very niceeee thank uuu for this

Leave a Reply

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