Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a TextArea in Android

Tags:

android

How do I display a TextArea for my android project? From xml, the only choice is TextField, multi lined. But thats editable. I need a TextArea which is only for displaying messages/text can't be edit/input by the user.

like image 891
Kenneth Lhv Avatar asked Dec 29 '11 10:12

Kenneth Lhv


People also ask

How to create textarea in Android?

So we have set android:inputType = textMultiLine to make our EditText support multiple line and keyboard's enter button will add lines instead of submit. And we set android:gravity = top|left, its inner gravity of EditText which moves the cursor to Top-Left corner of EditText. Which looks like TextArea of a webpage.

How to make EditText as textarea in Android?

Try to use EditText view - EditText documentation. You need something in style like EditText field or TextView? Use Text-view for this purpose it is the best suitable for your case. use background color to TextView, it solves your problem.

How do you edit a text box on Android?

Step 1: Create a new project in Android Studio and name it EditTextExample. Step 2: Now Open res -> layout -> xml (or) activity_main. xml and add following code. In this code we have added multiple edittext and a button with onclick functionality.

What is difference between textarea and textbox?

difference between text box and text area? The difference between the two is that input box will allow you to add one line of text, while the Text Area will allow you to add multiple lines of the text.


3 Answers

Try this:

<EditText         android:id="@+id/edit_text"         android:layout_width="match_parent"         android:layout_height="150dp"         android:inputType="text|textMultiLine"         android:gravity="top"/> 
like image 69
Vagner Gonçalves Gonçalves Avatar answered Oct 21 '22 19:10

Vagner Gonçalves Gonçalves


Use TextView inside a ScrollView

<ScrollView     android:id="@+id/ScrollView01"     android:layout_width="wrap_content"     android:layout_height="150dip">      <TextView         android:layout_width="wrap_content"         android:layout_height="wrap_content"/>  </ScrollView> 
like image 42
Sunil Kumar Sahoo Avatar answered Oct 21 '22 21:10

Sunil Kumar Sahoo


If you do not want to allow user to enter text TextView is the best option here. Any how you can also add EditText for this purpose. here is a sample code for that.

This would automatically show scrollbar if there is more text than the specified lines.

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textMultiLine"
    android:lines="8"
    android:maxLines="10"
    android:minLines="6"
    android:scrollbars="vertical" />

Edit: Adding attributes below to textView would make it a textArea that would not be editable.

android:lines="8"
android:maxLines="10"
android:minLines="6" // optional
like image 25
Inzimam Tariq IT Avatar answered Oct 21 '22 21:10

Inzimam Tariq IT