How to use TextView in android.

In this Article we create how to use Spinner in android using android studio.
The TextView view is used to display text to the user and optionally allows them to edit it. This is the most basic view and one that you will frequently use when you develop Android applications. If you need to allow users to edit the text displayed, you should use the subclass of TextView, EditText.

 

//Simple Textview Example in android
Step 1: Firstly, open your activity_main.xml file and add following code ( Open res -> layout -> activity_main.xml and add following code:)
// activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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.itbunch.com.textview.MainActivity">

<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60sp"
android:text="Hello World!"
android:textSize="30sp"
android:layout_centerHorizontal="true"
android:textColor="#0089fb"/>
</RelativeLayout>

 

Step 2: Let’s  open .Java file and and add following code (Open src -> package -> MainActivity.java and add following code: )

package com.itbunch.com.textview;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {
 TextView tv;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);

 tv=(TextView) findViewById(R.id.textview);
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
 return super.onCreateOptionsMenu(menu);
 }
}

 

Step 3: Open AndroidManifest.xml and add following code :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.itbunch.com.textview">

 <application
 android:allowBackup="true"
 android:icon="@mipmap/ic_launcher"
 android:label="@string/app_name"
 android:supportsRtl="true"
 android:theme="@style/AppTheme">
 <activity android:name=".MainActivity">
 <intent-filter>
 <action android:name="android.intent.action.MAIN" />

 <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
 </activity>
 </application>

</manifest>

Step 4 : Our output will be like this :
1

Thank You..

Tags: ,