0% found this document useful (0 votes)
8 views3 pages

EXP_7_GUI components

The document describes an Android application that utilizes GUI components, specifically a TextView and two Buttons. The first button changes the font size of the TextView, cycling between sizes, while the second button changes the text color through a predefined set of colors. The layout is defined in an XML file, which organizes the components vertically.

Uploaded by

amishav2004
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)
8 views3 pages

EXP_7_GUI components

The document describes an Android application that utilizes GUI components, specifically a TextView and two Buttons. The first button changes the font size of the TextView, cycling between sizes, while the second button changes the text color through a predefined set of colors. The layout is defined in an XML file, which organizes the components vertically.

Uploaded by

amishav2004
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/ 3

Experiment-07

Develop an application that uses GUI components.

Program: MainActivity.java
package com.example.expno7;

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 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;
}
});
}
}

Activity_main.xml
<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>

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