How to set edittext input type only uppercase in android programmatically

How to change all EditText inside text to uppercase programmatically.

In this tutorial we are converting EditText inside text to upper case at the application run time so firstly app user will insert lower case characters into EditText and when user clicks on button then it will change them to upper case. So here is the complete step by step tutorial for How to convert EditText all text to upper-case in android.

android-project-download-code-button

How to set edittext input type only uppercase in android programmatically.

Code for MainActivity.java file.

 package com.convertedittextalltextuppercase_android_examples.com;

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

public class MainActivity extends Activity {

 EditText edittext;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 edittext = (EditText)findViewById(R.id.editText1);
 
 edittext.setFilters(new InputFilter[]{new InputFilter.AllCaps()});
 
 }
}

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.convertedittextalltextuppercase_android_examples.com.MainActivity" >

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

</RelativeLayout>

Screenshot:

convert EditText all text to upper-case in android

Click here to download convert EditText all text to upper-case in android project.

One Comment

  1. Super Thank u

Leave a Reply

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