TextView in Android Studio with Programming Examples
Introduction of TextView in android:
As we know, TextView is a fundamental and vital UI element in an Android. As the name suggests, it plays a very crucial part in the UI experience and assists as to how information has to be presented to a user. Its widget being found on an Android can effectively be used in multiple situations. For instance, if we need some important information to be highlighted, then its substring has to be italicized or it has to be turned bold. Another situation, where TextView can be benefitted from, is that if the information has a hyperlink, which guides us to a particular web URL, then it has to be bridged with hyperlink and properly underlined.
TextView in Android exhibits text to a user and offers him the option to edit it programmatically. TextView is a complete text editor. Although it is basically configured as “editing not allowed” however, luckily, we can make use of this useful widget in order to edit and make changes to a text as desired.
A view can be treated as a parent class of TextView whereas a Text View as a subclass of view. As such, text view can be used as a component in app’s GUI inside a ViewGroup, or it may be deemed as a content view of the action.
A TextView case can be formed via pronouncing it inside an arrangement or design (XML file) or through exemplifying it programmatically (Java Class).
Attributes of Textview in android:
In order to configure a TextView in an XML file, we discuss the attributes (qualities or features) by means of which this task can better be comprehended.
id:
it is a feature or peculiar characteristic which is used to distinctively recognize a textview. An example code has been represented below, in which the id of a text view has to be set.
1 2 3 4 5 6 7 |
<TextView android:id="@+id/TxtDemo" android:layout_width="wrap_content" android:layout_height="wrap_content"/> |
gravity:
it is a non-compulsory attribute that is used in order to regulate the text orientation as left, right, center, top, bottom, center-vertical, center-horizontal, etc.
An example code with elucidation has been given below, where we have to set the right and left gravity for the text of a TextView.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <TextView android:id="@+id/TxtDemo" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Programming Digest" android:textSize="20sp" android:gravity="right"/> <TextView android:id="@+id/TxtDemo1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Programming Digest" android:textSize="20sp" android:gravity="left"/> </RelativeLayout> |
text:
this attribute is used to manage some sort of text in a text view. The text can be set in XML as well as in the java class.
An example code with explanation has been given below in which we set the text “Programming Digest” in a text view.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <TextView android:id="@+id/TxtDemo" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:textSize="25sp" android:text="Programming Digest" /> </RelativeLayout> |
In Java class:
An example code has been given below, in order to set the text in a textview programmatically, i.e. in the java class.
1 2 3 |
TextView textView = (TextView)findViewById(R.id.TxtDemo); textView.setText("Programming Digest"); |
textColor:
In order to set the color of a text in text view, this attribute is commonly used. In android for color, the RGB form is used.
An example code with explanation has been illustrated below, in which green color has been chosen in order to exhibit the proposed text.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <TextView android:id="@+id/TxtDemo" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:textSize="60sp" android:text="Programming Digest" android:textColor="#f0f0" /> </RelativeLayout> |
In Java class:
To set the color of the textview widget with java programming the following code example is used to set the color
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
package com.example.textviewdemo; import androidx.appcompat.app.AppCompatActivity; import android.graphics.Color; 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 textView = (TextView)findViewById(R.id.TxtDemo); textView.setTextColor(Color.GREEN); } } |
textSize:
We can make use of TextSize attribute in order to set size of the text of a text view. The text size can be set either in sp (scale independent pixel) or dp (density pixel).
An example code has been mentioned below in order to set the 50dp size for the text of a text view.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <TextView android:id="@+id/TxtDemo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Programming Digest" android:textSize="50dp" /> </RelativeLayout> |
In Java class:
An example code has been given below, in which we set the text size of a text view programmatically means in java class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
package com.example.textviewdemo; import androidx.appcompat.app.AppCompatActivity; import android.graphics.Color; 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 textView = (TextView)findViewById(R.id.TxtDemo); textView.setTextSize(50); } } |
textStyle:
In order to set the style of a text view, we make use of textStyle attribute.
In android there are only bold, italic, and normal text styles are available. If we use more than two styles then this “|” operator is used.
An example code with explanation has been given below in which we set the bold and italic text styles for text.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <TextView android:id="@+id/TxtDemo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Programming Digest" android:textSize="50dp" android:textStyle="bold" /> </RelativeLayout> |
Applying More than two textstyle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <TextView android:id="@+id/TxtDemo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Programming Digest" android:textSize="50dp" android:textStyle="bold|italic" /> </RelativeLayout> |
background:
in order to set background of a text, this attribute has to be used. The color or drawable can be set in the background of a text by making use of this background feature.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <TextView android:id="@+id/TxtDemo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Programming Digest" android:textColor="#FFFF00" android:background="#FF0000" android:textSize="50dp" /> </RelativeLayout> |
In Java class:
An example code in which we set the background color of a text view programmatically means in java class, has been given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
package com.example.textviewdemo; import androidx.appcompat.app.AppCompatActivity; import android.graphics.Color; 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 textView = (TextView)findViewById(R.id.TxtDemo); textView.setTextColor(Color.YELLOW); textView.setBackgroundColor(Color.RED); } } |
padding:
In order to set the padding from left, right, top or bottom, this attribute is used. In afore – mentioned background example code, we also set the 10dp padding from all the sides of text view.
An example code with explanation has been given below is the example, in which a black color is set for the background, white color for the text to be displayed and a 40dp padding set from all the side’s for text view.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <TextView android:id="@+id/TxtDemo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Programming Digest" android:textColor="#FFFF00" android:background="#FF0000" android:textSize="50dp" android:padding="40dp" /> </RelativeLayout> |
Typeface:
Android offers mainly 3 types of typefaces
sans
serif
monospace
The above three types of faces are to be projected under the “typeFace” attribute of the TextView in XML.
Use the following code and see the “typeFace” attribute of the TextView.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <TextView android:id="@+id/TxtDemo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Programming Digest" android:textColor="#FFFF00" android:background="#FF0000" android:textSize="30dp" android:padding="40dp" android:typeface="serif" /> </RelativeLayout> |
Text Shadow:
We can also set the shadow to the textview in android. The attributes used for shadows in android are given below
android:shadowDx:
This attribute is used to set the distance of the shadow in x axis and its value must be integer
android:shadowDy:
This attribute is used to set the distance of the shadow in y axis and its value must be integer
android:shadowRadius:
This attribute is used to set the radius of the textview shadow
Copy the below code and paste it and checks its output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <TextView android:id="@+id/TxtDemo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Programming Digest" android:textColor="#FFFF00" android:background="#FF0000" android:textSize="30dp" android:padding="40dp" android:typeface="serif" android:shadowColor="#000" android:shadowDx="20" android:shadowDy="30" android:shadowRadius="10" /> </RelativeLayout> |
Letter Spacing:
- An important property of the text view in android is letter spacing and capital letters.
- To set the buttons and tab layouts text, google material design recommended it to use uppercase letters
- The letter spacing also should be sustained according to the situation.
android:letterSpacing:
To giving the spaces between each character this attribute is used. And its value must be floating type.
Copy the below code and paste it and checks its output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <TextView android:id="@+id/TxtDemo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Programming Digest" android:textColor="#FFFF00" android:background="#FF0000" android:textSize="20dp" android:padding="40dp" android:typeface="serif" android:letterSpacing="0.5" /> </RelativeLayout> |
All Caps:
android:textAllCaps: To change all the characters in uppercase or in lowercase this attribute is used. And its value must be true or false.
Copy the below code and paste it and checks its output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <TextView android:id="@+id/TxtDemo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Programming Digest" android:textColor="#FFFF00" android:background="#FF0000" android:textSize="30dp" android:padding="40dp" android:typeface="serif" android:textAllCaps="true" /> </RelativeLayout> |
Example1: how to change Text of the TextView with button:
An example of TextView in which we display a text view and set the text in xml file and then change the text on button click event programmatically, has been given below. The final output and code are as follows:
Step 1: Create a new project and name it TextViewDemo.
Step 2: Open the res folder then click on activity_main.xml and add the following code. Here I created a button and a textview in Relative Layout.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <TextView android:id="@+id/TxtDemo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerVertical="true" android:layout_marginTop="3dp" android:background="#FF0000" android:text="Please click the button" android:textColor="#FFFF00" android:textSize="41dp" /> <Button android:id="@+id/btnclick" android:layout_width="278dp" android:layout_height="102dp" android:layout_below="@+id/TxtDemo" android:layout_alignParentStart="true" android:layout_alignParentEnd="true" android:layout_alignParentBottom="true" android:layout_marginStart="67dp" android:layout_marginTop="222dp" android:layout_marginEnd="66dp" android:layout_marginBottom="279dp" android:textSize="41dp" android:text="Click" /> </RelativeLayout> |
Step 3: than open MainActivity.java and add the following code. In this code I am changing the text of the textview when the user clicked on the button
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
package com.example.textviewdemo; import androidx.appcompat.app.AppCompatActivity; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView textView = (TextView)findViewById(R.id.TxtDemo); Button BtnClick = (Button) findViewById(R.id.btnclick); BtnClick.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { textView.setText("You clicked the button"); } }); } } |
Output:
Now run the app in Emulator or in a mobile phone, and click on the button. You will see text will be change when you clicked on the button.
When you clicked on the button the text of the textview will be changed, as you can see in the below figure
Example2: how use different Android TextView Attributes:
The usage of TextView in an android application, has been elaborated as follows.
First, create new android studio project and choose the name in my case I set application name as TextViewDemo. If you don’t know how to create and android studio application then click this article Toast Message in Android Studio.
Then click on res folder in res folder click on layout in layout folder open activity_main.xml file and paste the below code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<?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="wrap_content" android:layout_marginBottom="10dp" android:text="Welcome to Programmingdigest" android:textColor="#86AD33" android:textSize="20dp" android:textStyle="bold" /> <TextView android:id="@+id/TxtDemo" 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 Programming digest" android:textStyle="bold" android:textColor="#fff" android:background="#FF0000" 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 https://programmingdigest.com </LinearLayout> |
Once the layout has been created with required controls, we need to load the XML layout resource from our activity onCreate() callback method, for that open main activity file MainActivity.java and paste the below code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
package com.example.textviewdemo; import androidx.appcompat.app.AppCompatActivity; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView textView = (TextView)findViewById(R.id.TxtDemo); textView.setText("Welcome to Programmingdigest"); } } |
If you observe above code I am calling the layout using setContentView method in the form of R.layout.layout_file_name(R is class, layout is a method and then file name. I my case my xml file name is activity_main.xml so we used file name activity_main and I am setting text to one of my TextView control (TxtDemo) in our activity file.
Output of Android TextView Example
Now click on the run button you will see the output like as shown in below
Example3: how to Add Icons for TextView
- In android we can also use icons with textview
- In android There are three positions to add the icons with TextView. The positions are start, end, top, and bottom.
To create drawable icon for textview using asset studio simple right click on the drawable folder, then click on new in new dropdown list click on Vector asset
In asset studio click on clip Art for selecting the icon
Then select icon as per your required in my case I selected the back arrow icon, and then click on the ok button
Then set the icon name, and click on the next button
Finally, click on the finish button
As you can see the back.xml file is created
Repeat the same steps for the forward button
Copy the following code and check its output, to know how to add the drawable icons with Text View.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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" tools:context=".MainActivity"> <TextView android:id="@+id/Back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_centerVertical="true" android:background="#FF0000" android:drawableStart="@drawable/back" android:padding="10dp" android:text="Back" android:textAllCaps="true" android:textColor="#FFFF00" android:textSize="20dp" android:typeface="serif" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.254" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.499" /> <TextView android:id="@+id/Next" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/Back" android:layout_alignParentStart="true" android:layout_alignParentEnd="true" android:background="#FF0000" android:drawableEnd="@drawable/forward" android:padding="10dp" android:text="Next" android:textAllCaps="true" android:textColor="#FFFF00" android:textSize="20dp" android:typeface="serif" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.348" app:layout_constraintStart_toEndOf="@+id/Back" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.499" /> </androidx.constraintlayout.widget.ConstraintLayout> |
How to Add custom fonts in android
Any custom font can actually be used which we desire to have in our android applications. For this purpose, you can download any fonts from 1001freefonts website. For example, I downloaded Motion Picture font as an example.
Once your TTF font file is downloaded place it into asset/font folder
Here I am using a very basic layout. In this layout I use one textview with an id of TxtDemo.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <TextView android:id="@+id/TxtDemo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Programming Digest" android:textSize="60dp" /> </RelativeLayout> |
In order to set the custom font manually, we have to open activity file and insert this into the onCreate() method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
package com.example.textviewdemo; import androidx.appcompat.app.AppCompatActivity; import android.graphics.Color; import android.graphics.Typeface; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity { TextView TxtView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TxtView = findViewById(R.id.TxtDemo); Typeface font = Typeface.createFromAsset(getAssets(), "fonts/MotionPicture.ttf"); TxtView.setTypeface(font); } } |