Allow multi-line in EditText view in Android?

前端 未结 15 1567
既然无缘
既然无缘 2020-11-28 17:40

How to allow multi-line in Android\'s EditText view?

相关标签:
15条回答
  • 2020-11-28 18:02

    if some one is using AppCompatEditText then you need to set inputType="textMultiLine" here is the code you can copy


       <androidx.appcompat.widget.AppCompatEditText
            android:padding="@dimen/_8sdp"
            android:id="@+id/etNote"
            android:minLines="6"
            android:singleLine="false"
            android:lines="8"
            android:scrollbars="vertical"
            android:background="@drawable/rounded_border"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/_25sdp"
            android:layout_marginTop="32dp"
            android:layout_marginEnd="@dimen/_25sdp"
            android:autofillHints=""
    
            android:gravity="start|top"
            android:inputType="textMultiLine"
             />
    

    for background

       <?xml version="1.0" encoding="utf-8"?>
       <shape android:shape="rectangle" 
        xmlns:android="http://schemas.android.com/apk/res/android">
       <corners android:radius="@dimen/_5sdp"/>
       <stroke android:width="1dp" android:color="#C8C8C8"/>
       </shape>
    
    0 讨论(0)
  • 2020-11-28 18:04

    To disable number of lines that was previously assigned in theme use xml attribute: android:lines="@null"

    0 讨论(0)
  • 2020-11-28 18:06

    All of these are nice but will not work in case you have your edittext inside upper level scroll view :) Perhaps most common example is "Settings" view that has so many items that the they go beyond of visible area. In this case you put them all into scroll view to make settings scrollable. In case that you need multiline scrollable edit text in your settings, its scroll will not work.

    0 讨论(0)
  • 2020-11-28 18:07
    android:inputType="textMultiLine"
    

    This code line work for me. Add this code you edittext in your xml file.

    0 讨论(0)
  • 2020-11-28 18:09

    Just add this android:inputType="textMultiLine" in XML file on relevant field.

    0 讨论(0)
  • 2020-11-28 18:11

    Another neat thing to do is to use android:minHeight along with android:layout_height="wrap_content". This way you can set the size of the edit when it's empty, and when the user inputs stuff, it stretches according to how much the user inputs, including multiple lines.

    0 讨论(0)
提交回复
热议问题