Android Environment Setup- Studio - TextView Control - Android

What is Android TextView Control?

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

TextView Attributes

The attributes related to TextView control are listed below. Check Android official documentation for complete list of attributes and related methods which you can use to change these attributes are run time.

Sr.No. Attribute & Description
1
android:id
This is the ID which uniquely identifies the control.
2
android:capitalize
If set, specifies that this TextView has a textual input method and should automatically capitalize 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. 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

This example shows how to create your own Android application using Linear Layout and TextView.

Step Description
1

You will use Android studio to create an Android application and name it asdemounder a packagecom.example.demoas explained in theHello World Examplechapter.

2

Modifysrc/MainActivity.javafile to add necessary code .

2 Modify the default content ofres/layout/activity_main.xmlfile to include Android UI control.
3 No need to change default string constants at string.xml file. Android studio takes care of default string constants.
4 Run the application to launch Android emulator and verify the result of the changes done in the application.

Following is the content of the modified main activity file src/com.example.demo/MainActivity.java. This file can include each of the fundamental lifecycle methods.

Following will be the content of res/layout/activity_main.xml file:

Following will be the content of res/values/strings.xml to define two new constants:

Following is the default content of AndroidManifest.xml :


Let's try to run demo application. Assume that AVD is created while doing environment setup. To run the app from Android studio, open one of your project's activity files and click Run icon from the toolbar. Android studio installs the app on your AVD and starts it and it will display following Emulator window :

Android TextView


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Android Topics