如何将Edittext设置为多行?
How to set Edittext to multiline?
我曾尝试将我的 EditText 设置为多行,但它成功了。但是当我更改 EditText 上的一些东西以使其看起来有点酷时,它不再输入多行了。
<EditText
android:ems="10"
android:inputType="textMultiLine"
android:text=" "
android:id="@+id/reqdesc"
android:layout_width="fill_parent"
android:layout_height="110dp"
android:hint=" Enter your request here"
android:textSize="18sp"
android:maxLength="80"
android:background="@layout/rounded_border_edittext"
android:lines="8"
android:minLines="2"
android:gravity="top|left"
android:maxLines="4"
android:layout_marginTop="14dp"
android:layout_below="@+id/post"
android:layout_alignParentStart="true" />
试试这个:
找到你的Edittext
etReqdesc = (EditText) findViewById(R.id.reqdesc);
现在以编程方式调用:在 onCreate()
中
etReqdesc.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
etReqdesc.setSingleLine(false);
etReqdesc.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
您的编辑文本应如下所示:
<EditText
android:ems="10"
android:inputType="textMultiLine"
android:text=" "
android:id="@+id/reqdesc"
android:layout_width="fill_parent"
android:layout_height="110dp"
android:hint=" Enter your request here"
android:textSize="18sp"
android:background="@layout/rounded_border_edittext"
android:gravity="top|left"
android:layout_marginTop="14dp"
android:layout_below="@+id/post"
android:layout_alignParentStart="true" />
删除 android:maxLength="80"
属性。
reqdesc = (EditText) myView.findViewById(R.id.reqdesc);
reqdesc.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_FLAG_MULTI_LINE |
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
InputFilter[] fArray = new InputFilter[1];
fArray[0] = new InputFilter.LengthFilter(maxLength);
reqdesc.setFilters(fArray);
现在可以了,我把这几行代码放在onCreate下面。
我曾尝试将我的 EditText 设置为多行,但它成功了。但是当我更改 EditText 上的一些东西以使其看起来有点酷时,它不再输入多行了。
<EditText
android:ems="10"
android:inputType="textMultiLine"
android:text=" "
android:id="@+id/reqdesc"
android:layout_width="fill_parent"
android:layout_height="110dp"
android:hint=" Enter your request here"
android:textSize="18sp"
android:maxLength="80"
android:background="@layout/rounded_border_edittext"
android:lines="8"
android:minLines="2"
android:gravity="top|left"
android:maxLines="4"
android:layout_marginTop="14dp"
android:layout_below="@+id/post"
android:layout_alignParentStart="true" />
试试这个:
找到你的Edittext
etReqdesc = (EditText) findViewById(R.id.reqdesc);
现在以编程方式调用:在 onCreate()
etReqdesc.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
etReqdesc.setSingleLine(false);
etReqdesc.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
您的编辑文本应如下所示:
<EditText
android:ems="10"
android:inputType="textMultiLine"
android:text=" "
android:id="@+id/reqdesc"
android:layout_width="fill_parent"
android:layout_height="110dp"
android:hint=" Enter your request here"
android:textSize="18sp"
android:background="@layout/rounded_border_edittext"
android:gravity="top|left"
android:layout_marginTop="14dp"
android:layout_below="@+id/post"
android:layout_alignParentStart="true" />
删除 android:maxLength="80"
属性。
reqdesc = (EditText) myView.findViewById(R.id.reqdesc);
reqdesc.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_FLAG_MULTI_LINE |
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
InputFilter[] fArray = new InputFilter[1];
fArray[0] = new InputFilter.LengthFilter(maxLength);
reqdesc.setFilters(fArray);
现在可以了,我把这几行代码放在onCreate下面。