How to create textview in android using android studio ?

TextView :

In this tutorial we will learn about how to create a textview  android, how to get the text value using edittext from the user and set the text value on textview when button is clicked and their example .
TextView is an user interface design that displays text to the user . TextView is an android support widget which is used to show the text to the user .


1. Create a New Project :
Lets we start with a new project in Android Studio from File New Project ⇒
select Empty Activity and go through it.
2. Add TextView in android xml layout :
Add TextView to your XML Layout file i.e. activity_main.xml to create a textview to set the value for better user experience or just add the following code to activity_main.xml file .
<TextView
        android:id="@+id/textView"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="Hello World" />
3. Now find the TextView and set the text to textview:
Now set the text value to TextView using setText method in MainActivity.java file.
TextView textView = (TextView)findViewById(R.id.textView);
//To set the value on TextView
textView.setText("Technxt Code Labs");
Now run the project/app in android device or any Emulator to add TextView in android app.

For more details : How to create TextView in android using android studio ?

Comments