0% found this document useful (0 votes)
23 views5 pages

Android Text Size and Color Changer

The document contains a Java class for an Android application that allows users to change the font size and color of a TextView. It includes a layout file with a TextView and two buttons for changing the font size and color. The font size increases by 5 units with each button press, and the text color cycles through a set of predefined colors.

Uploaded by

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

Android Text Size and Color Changer

The document contains a Java class for an Android application that allows users to change the font size and color of a TextView. It includes a layout file with a TextView and two buttons for changing the font size and color. The font size increases by 5 units with each button press, and the text color cycles through a set of predefined colors.

Uploaded by

Vishavas Ichake
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

Mainactivity.

java
import [Link];

//import [Link];

import [Link]; import [Link];

import [Link];

import [Link];

import [Link];

public class MainActivity extends AppCompatActivity

int ch=1;

float font=30;

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

final TextView t= (TextView)

findViewById([Link]);

Button b1= (Button) findViewById([Link].button1);

[Link](new [Link]()

@Override

public void onClick(View v)

[Link](font);

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

font = 30;

});

Button b2= (Button) findViewById([Link].button2);

[Link](new [Link]() {

@Override

public void onClick(View v) {

switch (ch) {

case 1:

[Link]([Link]);

break;

case 2:

[Link]([Link]);

break;

case 3:

[Link]([Link]);

break;

case 4:

[Link]([Link]);

break;

case 5:

[Link]([Link]);

break;

case 6:
[Link]([Link]);

break;

ch++;

if (ch == 7)

ch = 1;

});

}
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="[Link]
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