Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Develop a program to implement TextView and EditText

INTRODUCTION

In android, TextView is a user interface control that is used to set and display the text
to the user based on our requirements.
In android, we can create a TextView control in two ways either in XML layout file or create it
in Activity file programmatically.
In android, EditText is a user interface control which is used to allow the user to enter or
modify the text. While using EditText control in our android applications, we need to specify
the type of data the text field can accept using the inputType attribute.
For example, if it accept plain text, then we need to specify the inputType as “text”. In case
if EditText field is for password, then we need to specify the inputType as “textPassword”.
In android, EditText control is an extended version of TextView control with additional
features and it is used to allow users to enter input values.
In android, we can create EditText control in two ways either in XML layout file or create it
in Activity file programmatically.

SIET PANIV,(POLY) 1
Develop a program to implement TextView and EditText

DESCRIPTION
TextView
In Android ,TextView displays text to the user and optionally allows them to
edit it programmatically. TextView is a complete text editor, however basic class is configured to
not allow editing but we can edit it.
View is the parent class of TextView.Being a subclass of view the text view component can be
used in your app’s GUI inside a ViesGroup ,or as the content view of an activity.
A TextView displays text to the use and optinally allows them to edit it.A TextView is a
complete text editor,however the basic class is configured to not allow editing .
The TextView control will act as like label control and it won’t allow users to edit the text.

EditText
A EditText is an overlay over TextView that configures itself to be editable.
It is the predefined subclass of TextView that includes rich editing capabilities.
EditText is one of the important UI element.
EditText referes to the widget that displays an empty text field in which a user can enter the
required text and this text is further used inside the application. In this article its been discussed
to implement to special type of text fields,those are called Material Design Edittext.
Have a look at normal edit text in android and Material design Text fields in android. The design
and the easy to use implementation makes them different from normal Edittext fields.
In android, we can create EditText control in two ways either in XML layout file or create it in Activity file
programmatically
This is how we can use EditText control in android applications to allow the user to enter or modify the text
based on our requirements.

SIET PANIV,(POLY) 2
Develop a program to implement TextView and EditText

PROGRAM

PROGRAM FOR TEXTVIEW:


package com.tutlane.textviewexample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv = (TextView)findViewById(R.id.textView2);
tv.setText("Welcome to Tutlane");

}
OTPUT:
“Welcome to Tutlane”

SIET PANIV,(POLY) 3
Develop a program to implement TextView and EditText

PROGRAM FOR EDITTEXT


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/textView1"
android:layout__width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="Welcome to Tutlane"
android:textColor="#86AD33"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="Welcome to Tutlane"
android:textColor="#86AD33"
android:layout_marginBottom="15dp"/>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="email|web"
android:text="For more details visit http://tutlane.com and send mail to
support@tutlane.com" />
</LinearLayout>

SIET PANIV,(POLY) 4
Develop a program to implement TextView and EditText

OUTPUT:

SIET PANIV,(POLY) 5
Develop a program to implement TextView and EditText

SYSTEM REQUIREMENT

Sr.No Name of Specification Quantity Remark


Resources/Material

1 Computer System Windows 1 Available

7,RAM 2GB

2 Software Python IDE 1 Available

SIET PANIV,(POLY) 6
Develop a program to implement TextView and EditText

Advantages

• This text is wrapped in a deform TextView around the other view to the right.
• This is the similar to putting an image object floating inside a TextView,if that is at all
possible.

SIET PANIV,(POLY) 7
Develop a program to implement TextView and EditText

CONCLUSION

The article intended to cover the concept of creating text controls and the
basics of Edit text property in Android Application.
We learned that we can configure the keyboard that EditTexts pull up to suite our data input
needs, as well as make them span multiple lines high for longer text input.

SIET PANIV,(POLY) 8
Develop a program to implement TextView and EditText

REFERENCE

https://www.tutorialspoint.com/android
https://stuff.mit.edu
https://www.tutorialspoint.com/android/android_advanced_tutorial.pdf
https://developer.android.com

SIET PANIV,(POLY) 9
Develop a program to implement TextView and EditText

Example:

This is how we can use EditText control in android applications to allow the user to enter or modify the text
based on our requirements.

SIET PANIV,(POLY) 10
Develop a program to implement TextView and EditText

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/textView1"
android:layout__width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="Welcome to Tutlane"
android:textColor="#86AD33"
android:textSize="20dp"
android:textStyle="bold" />

SIET PANIV,(POLY) 11
Develop a program to implement TextView and EditText

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:textAllCaps="true" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to Tutlane"
android:textStyle="bold"
android:textColor="#fff"
android:background="#7F3AB5"
android:layout_marginBottom="15dp"/>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="email|web"
android:text="For more details visit http://tutlane.com and send mail to
support@tutlane.com" />
</LinearLayout>

MainActivity.java
package com.tutlane.textviewexample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv = (TextView)findViewById(R.id.textView2);

SIET PANIV,(POLY) 12
Develop a program to implement TextView and EditText

tv.setText("Welcome to Tutlane");

SIET PANIV,(POLY) 13

You might also like