TextView in android is used to display texts. It does not allow the user to edit the texts in it.
In this post, we are going to discuss TextView in detail and how to use it.

TextView from layout XML file:

As you can see in the above code, we have used four basic properties width, height, text, and textSize. There are many other properties, but for simplicity, we have used only these four properties for now.

Here android:layout_width=”wrap_content” and android:layout_height=”wrap_content”, these two are mandatory properties. Using android:layout_width=”wrap_content”, you can set the width of your TextView and using  android:layout_height=”wrap_content”, you can set the height of your TextView.

To set the text of your TextView you can use this android:text=” ” property. And to set the size of the TextView text, the property is android:textSize=” “ 

You have to place a TextView inside a root layout. i.e LinearLayout, RelativeLayout.

So the complete code will look something like this:

Now when you run the app, the output will look like this:

textview-android

Though the TextView in android is not editable, but you can make it selectable. So that user can select and copy texts from the TextView.

There is a property, android:textIsSelctable=” “, to make it selectable set the property to true.

TextView Android tutorial for absolute beginners
Tagged on:

One thought on “TextView Android tutorial for absolute beginners

  • April 16, 2017 at 8:08 am
    Permalink

    Excellent post. Keep writing such kind of information on your
    blog. Im really impressed by your site.
    Hi there, You’ve performed a great job. I will certainly digg it and personally recommend to my friends.
    I am sure they’ll be benefited from this website.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *