How to create a TextArea in Android

前端 未结 11 1858
醉话见心
醉话见心 2021-02-06 22:16

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 messa

相关标签:
11条回答
  • 2021-02-06 22:56

    Its really simple, write this code in XML:

    <EditText
        android:id="@+id/fname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="First Name"
    />
    
    0 讨论(0)
  • 2021-02-06 22:56

    Try this:

    <EditText
            android:id="@+id/edit_text"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:inputType="text|textMultiLine"
            android:gravity="top"/>
    
    0 讨论(0)
  • 2021-02-06 22:58
    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="100dp">
    <EditText
        android:id="@+id/question_input"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:ems="10"
        android:inputType="text|textMultiLine"
        android:lineSpacingExtra="5sp"
        android:padding="5dp"
        android:textAlignment="textEnd"
        android:typeface="normal" />
    
    </android.support.v4.widget.NestedScrollView>
    
    0 讨论(0)
  • 2021-02-06 23:00
    <EditText
        android:id="@+id/comments_textbox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="comments"
        android:inputType="textMultiLine"
        android:longClickable="false" />
    

    use it to create multi line text box like textArea in Html

    0 讨论(0)
  • 2021-02-06 23:04

    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
    
    0 讨论(0)
提交回复
热议问题