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.
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.
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.
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.
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.
Try this:
<EditText android:id="@+id/edit_text" android:layout_width="match_parent" android:layout_height="150dp" android:inputType="text|textMultiLine" android:gravity="top"/>
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>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With