0% found this document useful (0 votes)
24 views4 pages

Termwork-1: Source Code

The document contains XML code for a layout with a TextView and two Buttons. It also contains Java code to change the font size and color of the TextView when the Buttons are clicked.

Uploaded by

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

Termwork-1: Source Code

The document contains XML code for a layout with a TextView and two Buttons. It also contains Java code to change the font size and color of the TextView when the Buttons are clicked.

Uploaded by

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

TERMWORK-1

SOURCE CODE
XML CODE

<?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:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<TextView

android:id="@+id/tv"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Hello world"

android:textSize="80px"

android:textStyle="bold"

android:textColor="@color/black"

android:layout_gravity="center"/>

<Button

android:id="@+id/f"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="Change Font Size"

android:layout_gravity="center_horizontal"/>

<Button

android:id="@+id/c"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text=" Change Colour "

android:layout_gravity="center"/>

</LinearLayout>

<?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>

</resources>

JAVA CODE

package com.example.termwork1;
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 {

float font=30;

int ch=1;

String colour="orange";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Button f,c;

TextView tv;

f=findViewById(R.id.f);

c=findViewById(R.id.c);

tv=findViewById(R.id.tv);

f.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

tv.setTextSize(font);

font+=5;
if(font==50){

font=30;

});

c.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

switch (ch){

case 1:tv.setTextColor(Color.GREEN);

break;

case 2:tv.setTextColor(Color.BLUE);

break;

case 3: tv.setTextColor(Color.RED);

break;

case 4:tv.setTextColor(Color.YELLOW);

break;

ch++;

if (ch==5){

ch=1;

});

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