title: Increase and decrease text size on button click in Android
body: <p>I am a beginner.</p>
  
  <p>I want to increase text size of a textview when a button is clicked, also decrease the size when another button is clicked.</p>
  
  <p>But the problem is, it's only increasing, the size of text is not decreasing.</p>
  
  <p>I'm getting text size using getTextSize() method.</p>
  
  <p>Here is my XML</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".textSize"&gt;
  
      &lt;Button
          android:id="@+id/up"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_marginStart="16dp"
          android:layout_marginEnd="8dp"
          android:layout_marginBottom="124dp"
          android:text=" Size Up"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toStartOf="@+id/down"
          app:layout_constraintStart_toStartOf="parent" /&gt;
  
      &lt;Button
          android:id="@+id/down"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_marginStart="8dp"
          android:layout_marginEnd="24dp"
          android:layout_marginBottom="124dp"
          android:text=" Size down"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toEndOf="@+id/up" /&gt;
  
      &lt;TextView
          android:id="@+id/myTextView"
          android:layout_width="328dp"
          android:layout_height="58dp"
          android:layout_marginStart="8dp"
          android:layout_marginTop="216dp"
          android:layout_marginEnd="8dp"
          android:text="TextView"
          android:textSize="30dp"
          app:layout_constraintEnd_toEndOf="@+id/down"
          app:layout_constraintStart_toStartOf="@+id/up"
          app:layout_constraintTop_toTopOf="parent" /&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  
  <p>Here is Java code:</p>
  
  <pre><code>package com.example.toast;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.TextView;
  
  public class textSize extends AppCompatActivity {
  TextView textView;
  Button upButton, downButton;
  Float textSize,diff=2.0f;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_text_size);
  
          upButton=findViewById(R.id.up);
          downButton= findViewById(R.id.down);
          textView=findViewById(R.id.myTextView);
  
          upButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  textSize=textView.getTextSize();
                  textSize = textSize+diff;
             textView.setTextSize(textSize);
  
              }
          });
          downButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  textSize=textView.getTextSize();
                  textSize = textSize-diff;
                  textView.setTextSize(textSize);
  
              }
          });
  
      }
  }
  </code></pre>
  
  <p>Please tell me where I'm making mistake.</p>