Skip to content
Related Articles

Related Articles

How to Increase or Decrease TextView Font Size in Android Programmatically?
  • Difficulty Level : Hard
  • Last Updated : 18 Feb, 2021

In this App, we are going to learn how to increase or decrease TextView Font Size in android programmatically. Like we have seen that in many apps we sometimes want to enlarge the text. So here basically we are going to implement that. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language. 

Increase or Decrease TextView Font Size in Android Programmatically Sample GIF

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Working with the activity_main.xml file

Here we are basically creating two Buttons to increase and decrease the text size. And one TextView that contains Loram Ipsum dummy text. Below is the code for the activity_main.xml file. 


<?xml version="1.0" encoding="utf-8"?>
            android:text="Increase" />
            android:text="Decrease" />
        android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sem augue,
                      aliquam bibendum fringilla quis, volutpat ut arcu. Sed nulla metus, gravida
                      id pulvinar quis, rhoncus in velit. Pellentesque semper mollis leo,
                      vitae molestie risus. Curabitur nec suscipit tortor. Quisque non purus eu
                      quam pretium mollis sed in turpis. Duis elit magna, ullamcorper vitae elementum
                      in, auctor eget ligula. Maecenas ultricies diam non nisl facilisis porta.
                      Suspendisse diam ante, accumsan sit amet enim nec, bibendum semper arcu.
                      Nunc a imperdiet odio. Morbi id est finibus ex mollis interdum vulputate non
                      eros. Interdum et malesuada fames ac ante ipsum primis in faucibus. Vestibulum 
                      sit amet dictum ante, vitae condimentum augue. Proin ultricies enim nisl,
                      eu pharetra arcu venenatis sit amet. Pellentesque sodales, justo eu iaculis
                      rhoncus, magna mi ullamcorper enim, a mattis neque sapien eu nisi. Duis a 
                      turpis euismod nibh mattis egestas sed vel sem. Maecenas non tempor tellus,
                      id facilisis erat. Nullam id commodo nisi. Ut sed arcu lectus. Mauris lacus 
                      libero, pharetra et neque vitae, tincidunt dapibus magna. Sed non scelerisque 
                      leo, non pharetra mi. In sollicitudin metus ut lacus vestibulum efficitur.
                      Sed cursus pellentesque ante at vehicula. Nunc eros metus, mattis at aliquet at,
                      euismod et libero.!"
        app:layout_constraintTop_toTopOf="parent" />

This is how our activity will look:


Step 3: Working with the file

Go to the file and refer to the following code. Below is the code for the file. Comments are added inside the code to understand the code in more detail.


import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
    Button increase, decrease;
    private float ourFontsize = 14f;
    TextView text;
    protected void onCreate(Bundle savedInstanceState) {
        increase = findViewById(;
        decrease = findViewById(;
        text = findViewById(;
        increase.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // increasing the size by 4 unit
                ourFontsize += 4f;
                // assigning new textsize to our text
                text.setTextSize(TypedValue.COMPLEX_UNIT_SP, ourFontsize);
        decrease.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // decreasing the size by 4 unit
                ourFontsize -= 4f;
                // assigning new textsize to our text
                text.setTextSize(TypedValue.COMPLEX_UNIT_SP, ourFontsize);


Want a more fast-paced & competitive environment to learn the fundamentals of Android?
Click here to head to a guide uniquely curated by our experts with the aim to make you industry ready in no time!
My Personal Notes arrow_drop_up
Recommended Articles
Page :