Capitalize all textview text programmatically android

Convert Normal written text to upper case on button click in android TextView using setAllCaps(true) function.

With the use of setAllCaps() function application developer can dynamically change normal upper + small text into only capital words. SO here is the complete step by step tutorial for Capitalize all textview text programmatically android.

android-project-download-code-button

 

How to Capitalize all textview text programmatically android.

Code for MainActivity.java file.

package com.textviewuppercase_android_examples.com;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


public class MainActivity extends Activity {

 Button UpperCase;
 TextView Ntext;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 UpperCase = (Button)findViewById(R.id.button1);
 Ntext = (TextView)findViewById(R.id.textView1);
 
 UpperCase.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 
 Ntext.setAllCaps(true);
 
 }
 });
 
 }
}

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

 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:text="Sample Text on TextView"
 android:textAppearance="?android:attr/textAppearanceLarge" />

 <Button
 android:id="@+id/button1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/textView1"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="17dp"
 android:text="Click Here to Capitalize textview text programmatically android" />
 
</RelativeLayout>

Screenshot:

upper case

Capitalize all textview text programmatically android

Click Here to Download Capitalize all textview text programmatically android project.

Leave a Reply

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