android---EditText的多行输入框

<EditText
android:id="@+id/edt_order_note_text"
android:layout_width="match_parent"
android:layout_height="90dp"
android:padding="5dp"
android:minLines="5"
android:gravity="top"
android:background="@drawable/order_edt_note_bg"
android:textColor="@color/black"
android:textSize="14sp"/>

EditText的多行输入,涉及到的属性有:

minLines是只输入的最小行数,
gravity="top"是为了让文字从输入框上面依次排版下来,而不是显示在输入框中间。
使用maxLines的EditText最大行数为3行,当输入的内容超过3行后, 它形状的大小不会根据输入内容的多少而改变, 反正它显示的内容就是3行 而使用minLines的EditText是至它至少显示3行内容 (包括内容为空时,可对比图片),当输入的内容超过3行后, 它形状的大小根据输入内容的多少而改变。

@drawable/order_edt_note_bg是一个输入框背景的xml,order_edt_note_bg.xml代码如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <corners android:radius="6dp" >
    </corners>
    <stroke
        android:width="1dp"
        android:color="#c0c0c0" >
    </stroke>
</shape>


猜你喜欢

转载自www.cnblogs.com/tc310/p/10701933.html
今日推荐