How to Create Text View In Android Studio.

How to Create Text View In Android Studio.

TextView displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however, the basic class is configured to not allow editing.


Sr.No.Attribute & Description
1

android: id

This is the ID that uniquely identifies the control.

2

android: capitalize

If set specifies that this TextView has a textual input method and should automatically capitalize on what the user types.

  • Don't automatically capitalize anything - 0
  • Capitalize the first word of each sentence - 1
  • Capitalize the first letter of every word - 2
  • Capitalize every character - 3
3

android: cursorvisible

Makes the cursor visible (the default) or invisible. The default is false.

4

android: editable

If set to true, specifies that this TextView has an input method.

5

android:fontFamily

Font family (named by string) for the text.

6

android:gravity

Specifies how to align the text by the view's x- and/or y-axis when the text is smaller than the view.

7

android:hint

Hint text to display when the text is empty.

8

android:inputType

The type of data being placed in a text field. Phone, Date, Time, Number, Password etc.

9

android:maxHeight

Makes the TextView be at most this many pixels tall.

10

android:maxWidth

Makes the TextView be at most this many pixels wide.

11

android:minHeight

Makes the TextView be at least this many pixels tall.

12

android:minWidth

Makes the TextView be at least this many pixels wide.

13

android:password

Whether the characters of the field are displayed as password dots instead of themselves. Possible value either "true" or "false".

14

android:phoneNumber

If set, specifies that this TextView has a phone number input method. Possible value either "true" or "false".

15

android:text

Text to display.

16

android:textAllCaps

Present the text in ALL CAPS. Possible value either "true" or "false".

17

android:textColor

Text color. May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

18

android:textColorHighlight

Color of the text selection highlight.

19

android:textColorHint

Color of the hint text. May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

20

android:textIsSelectable

Indicates that the content of a non-editable text can be selected. Possible value either "true" or "false".

21

android:textSize

Size of the text. Recommended dimension type for text is "sp" for scaled-pixels (example: 15sp).

22

android:textStyle

Style (bold, italic, bolditalic) for the text. You can use or more of the following values separated by '|'.

  • normal - 0
  • bold - 1
  • italic - 2
23

android:typeface

Typeface (normal, sans, serif, monospace) for the text. You can use or more of the following values separated by '|'.

  • normal - 0
  • sans - 1
  • serif - 2
  • monospace - 3
Example -
Activity_main.xml
     This is a layout file In Android Studio
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:background="#F3F3F3"
android:gravity="center"
android:id="@+id/textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="My First Text View "
android:textColor="#FF0101"
android:textSize="30dp"
android:textStyle="bold"
android:layout_margin="10dp"
android:padding="20dp"
android:textAllCaps="false"
/>

</LinearLayout>
MainActivity.Java
this is a Codeing file in Android Studio
package com.example.MyFirstTextView;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView=findViewById(R.id.textview);
textView.setText("My First Text View");
}
}
output is-

this is a complete text view example in android.
please Comment this if any issue in code. I will help you as possible.


Comments

Popular posts from this blog

How to Integrate or Work with Open Street Map (OSM) in an Android App (Kotlin)

ListView in android with api and volley Network Library in android Studio.

how to implement OpenStreetMap in android