Change font size in EditText android programmatically

How to increase/decrease text size of EditText inside typed text, Create EditText with custom font size.

In this tutorial we are setting up EditText font size so app developer can manually manage Edittext font size. So here is the complete step by step tutorial for Change font size in EditText android programmatically.

android-project-download-code-button

How to Change font size in EditText android programmatically.

Code for MainActivity.java file.

 package com.edittextfontsize_android_examples.com;

import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;

public class MainActivity extends Activity {

 EditText editText1,editText2;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 editText1 = (EditText)findViewById(R.id.editText1);
 editText2 = (EditText)findViewById(R.id.editText2);
 
 //EditText with 15 dp font size.
 editText1.setTextSize(15);
 
 //EditText with 20 dp font size.
 editText2.setTextSize(20);
 
 }


}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.edittextfontsize_android_examples.com.MainActivity" >

 <EditText
 android:id="@+id/editText1"
 android:layout_width="230dp"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:ems="10"
 android:hint="EditText - 1" >

 </EditText>

 <EditText
 android:id="@+id/editText2"
 android:layout_width="230dp"
 android:layout_height="wrap_content"
 android:layout_below="@+id/editText1"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="20dp"
 android:ems="10"
 android:hint="EditText - 2" />
 
</RelativeLayout>

Screenshot:

Change font size in EditText android programmatically

Click here to download Change font size in EditText android programmatically project.

Leave a Reply

Your email address will not be published. Required fields are marked *