| Attribute | Description |
|---|---|
| android:id | This is the ID which uniquely identifies the control. |
| android:text | Text to display. |
| android:textAllCaps | Present the text in ALL CAPS. Possible value either true or false. |
| android:textColor | Text color. May be a color value, in the form of #rgb, #argb, #rrggbb, or #aarrggbb. |
| android:textSize | Size of the text. Recommended dimension type for text is sp for scaled-pixels (example: 15sp). |
| android:textStyle | Style (bold, italic, bolditalic) for the text. You can use or more of the following values separated by '|'. |
| android:typeface | Typeface (normal, sans, serif, monospace) for the text. You can use or more of the following values separated by '|'. |
| android:padding | Space between the border and the actual view's content |
| android:layout_margin | Spaces outside the border |
| android:background | Apply background color to view |
| android:layout_gravity | sets the gravity of the View or Layout in its parent. |
| android:gravity | Sets the gravity of the content of the View its used on. |
| android:hint | -- |
| android:ems | -- |
<TextView
android:id="@+id/tvRegistration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Registration"
android:textColor="#FFF"
android:textSize="18sp"
android:textStyle="bold" />
Result : Step 1 : XML FileStep 2 : Java FileStep 1 : res/layout/textview_ex.xml
<?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:orientation="vertical" >
<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This is a Textview" />
</LinearLayout>
Step 2 : src/TextviewDemo.java
package com.example.androidcollegeppt;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class TextviewDemo extends Activity{
TextView tv_title;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.textview_ex);
tv_title=(TextView)findViewById(R.id.tv_title);
}
}
Result : Step 1 : XML FileStep 2 : Java FileStep 1 : res/layout/textview_ex.xml
<?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:orientation="vertical" >
<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This is a Textview" />
</LinearLayout>
Step 2 : src/TextviewDemo.java
package com.example.androidcollegeppt;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class TextviewDemo extends Activity{
TextView tv_title;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.textview_ex);
tv_title=(TextView)findViewById(R.id.tv_title);
tv_title.setText("Data from Java File");
}
}
<?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:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Textview" />
</LinearLayout>
Example :
<?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:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Textview" />
</LinearLayout>
Example :
<?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:orientation="vertical" >
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is TextView"
/>
</LinearLayout>
<?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:orientation="vertical" >
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="25dp"
android:background="#FFFF00"
android:padding="8dp"
android:text="This is TextView"
android:textColor="#000000"
/>
</LinearLayout>
<?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:orientation="vertical" >
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="25dp"
android:background="#FFFF00"
android:padding="8dp"
android:text="This is TextView"
android:textColor="#000000"
android:textSize="18sp" />
</LinearLayout>
Result :
<?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:orientation="vertical" >
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:background="#FF0000"
android:layout_height="wrap_content"
android:text="This is TextView" />
</LinearLayout>
Result :
<?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:orientation="vertical" >
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:background="#FF0"
android:padding="8dp"
android:layout_height="wrap_content"
android:text="This is TextView" />
</LinearLayout>
Result :
<?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:orientation="vertical" >
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:background="#FF0"
android:padding="8dp"
android:layout_margin="25dp"
android:layout_height="wrap_content"
android:text="This is TextView" />
</LinearLayout>
Result :
<?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:orientation="vertical" >
<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFF00"
android:gravity="center_horizontal"
android:text="This is TextView" />
</LinearLayout>
Result :
<?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:orientation="vertical" >
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#FFFF00"
android:text="This is TextView" />
</LinearLayout>