在Android的EditText视图中允许多行?

如何在Android的EditText视图中允许多行?

12个解决方案

981 votes

默认情况下,Android中的所有EditText小部件都是多行的。

以下是一些示例代码:

android:inputType="textMultiLine"

android:lines="8"

android:minLines="6"

android:gravity="top|left"

android:maxLines="10"

android:layout_height="wrap_content"

android:layout_width="match_parent"

android:scrollbars="vertical"

/>

Shardul answered 2019-03-31T12:45:49Z

199 votes

你可能会发现它更好用:

...

android:inputType="textMultiLine"

/>

这是因为不推荐使用android:singleLine。

Knossos answered 2019-03-31T12:46:22Z

37 votes

这对我有用,实际上这两个属性很重要:inputType和lines。 此外,您可能需要一个滚动条,下面的代码显示了如何制作一个:

android:id="@+id/addr_edittext"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:gravity="top|left"

android:inputType="textEmailAddress|textMultiLine"

android:lines="20"

android:minLines="5"

android:scrollHorizontally="false"

android:scrollbars="vertical" />

acoustic answered 2019-03-31T12:46:50Z

11 votes

这是我使用的方式,它的工作也很好。 希望,这会对某人有所帮助。

android:id="@+id/EditText02"

android:gravity="top|left"

android:inputType="textMultiLine"

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:lines="5"

android:scrollHorizontally="false"

/>

干杯! ...谢谢。

Nandagopal T answered 2019-03-31T12:47:24Z

9 votes

试试这个,将这些行添加到您的编辑文本视图中,我将添加我的。 确保你理解它

android:overScrollMode="always"

android:scrollbarStyle="insideInset"

android:scrollbars="vertical"

android:inputType="textMultiLine"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:id="@+id/editText_newprom_description"

android:padding="10dp"

android:lines="5"

android:overScrollMode="always"

android:scrollbarStyle="insideInset"

android:minLines="5"

android:gravity="top|left"

android:scrollbars="vertical"

android:layout_marginBottom="20dp"/>

并在你的java类上使用onclicklistener编辑这个编辑文本如下,我将根据你的添加我的,chane名称。

EditText description;

description = (EditText)findViewById(R.id.editText_newprom_description);

description.setOnTouchListener(new View.OnTouchListener() {

@Override

public boolean onTouch(View view, MotionEvent motionEvent) {

view.getParent().requestDisallowInterceptTouchEvent(true);

switch (motionEvent.getAction() & MotionEvent.ACTION_MASK){

case MotionEvent.ACTION_UP:

view.getParent().requestDisallowInterceptTouchEvent(false);

break;

}

return false;

}

});

这对我来说很好

Chathura Jayanath answered 2019-03-31T12:48:00Z

8 votes

EditText具有singleLine属性。 您可以在XML中设置或通过调用setSingleLine(false);[http://developer.android.com/reference/android/widget/TextView.html#setSingleLine%28%29]

milan answered 2019-03-31T12:48:26Z

5 votes

所有这些都很好,但是如果你在上层滚动视图中有你的edittext,它将不起作用:)也许最常见的例子是“设置”视图,它有很多项目,超出了可见区域。 在这种情况下,您将它们全部放入滚动视图以使设置可滚动。 如果您在设置中需要多行可滚动编辑文本,则其滚动将不起作用。

Cynichniy Bandera answered 2019-03-31T12:48:52Z

4 votes

要禁用先前在主题使用xml属性中分配的行数:android:lines="@null"

Oleg Bozhko answered 2019-03-31T12:49:27Z

3 votes

android:id="@id/editText" //id of editText

android:gravity="start" // Where to start Typing

android:inputType="textMultiLine" // multiline

android:imeOptions="actionDone" // Keyboard done button

android:minLines="5" // Min Line of editText

android:hint="@string/Enter Data" // Hint in editText

android:layout_width="match_parent" //width editText

android:layout_height="wrap_content" //height editText

/>

Yogesh Sarvaiya answered 2019-03-31T12:49:47Z

1 votes

我从[http://www.pcsalt.com/android/edittext-with-single-line-line-wrapping-and-done-action-in-android/]了解到这一点,虽然我自己不喜欢这个网站。 如果您想要多行但是想要将输入按钮保留为发布按钮,请将listview的“水平滚动”设置为false。

listView.setHorizontallyScrolling(false);

如果它在xml中不起作用,那么以编程方式执行它会很奇怪。

listView.setHorizontallyScrolling(false);

Fire3galaxy answered 2019-03-31T12:50:40Z

0 votes

另一个巧妙的做法是使用android:minHeight和android:layout_height="wrap_content".这样你就可以设置编辑时的大小,当用户输入内容时,它会根据用户输入的内容(包括多行)进行扩展。

instanceof answered 2019-03-31T12:51:15Z

0 votes

android:hint="Address"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:inputType="textMultiLine|textNoSuggestions"

android:id="@+id/edittxtAddress"

android:layout_marginLeft="@dimen/textsize2"

android:textColor="@android:color/white"

android:scrollbars="vertical"

android:minLines="2"

android:textStyle="normal" />

并在活动中删除“\ n”是用户按下一行

String editStr= edittxtAddress.getText().toString().trim();

MyString= editStr.replaceAll("\n"," ");

Kapil Parmar answered 2019-03-31T12:51:50Z

android edittext设置多行,在Android的EditText视图中允许多行?相关推荐

  1. Android Studio 设置打开layout.xml文件的默认视图

    Android Studio 设置打开layout.xml文件的默认视图 Android Studio 设置打开layout.xml文件的默认视图 androd studio 在使用的时候打开我们自己 ...

  2. android动态设置maxWidth,如何使用android:maxWidth?

    I want to set a maximum width of an edit box. 在你的例子中: android:layout_width="fill_parent" a ...

  3. android 微信设置圆角边框代码,Android编程实现圆角边框的方法

    本文实例讲述了Android编程实现圆角边框的方法.分享给大家供大家参考,具体如下: 设置边框圆角可以在drawable-mdpi目录里定义一个xml: android:topRightRadius= ...

  4. android webview 设置cookie时间,解决Android webview设置cookie和cookie丢失的问题

    Android页面嵌套了一个h5,H5页面内部有用户登陆页面,发现h5页面的登陆功能无法使用,一直登陆失败.和web那边商量一会,发现js写入的cookie丢失了.所有需要Android这边在重写写入 ...

  5. android 铃声设置失败,无法通过Android代码设置铃声

    我正在开发一个应用程序,它将随机设置用户已选择的铃声列表中的铃声.无法通过Android代码设置铃声 虽然我的代码适用于Android N及以上版本,但我遇到了Android M及以下版本的问题.我为 ...

  6. android 动态设置style属性值,android中的style属性值,以及一些预定义样式

    Android平台定义的主题样式:android:theme="@android:style/Theme.Dialog" // 将一个Activity显示为对话框模式 androi ...

  7. css表格设置行列的颜色,CSS:为表格中的选定行设置颜色

    我需要将以下功能添加到我的表中:当用户单击某行(选择它)时,该行用颜色#FFCF8B标记(与hover相同).我试过#newspaper-b tbody tr.selected td,但它不起作用.C ...

  8. textarea 行数限制_在一个TextArea中如何限制行数和字符数

    在网上,已经有很多关于在一个textbox限制允许的字符数量.但是如果需要,在textbox中如何去统计和限制行数呢.这里有一个解决方案,使用客户端的Javascript去限制TextArea的内容为 ...

  9. 计算机做表格的行高和列宽,表格中列和行的插入与删除及行高和列宽的调整——想象力电脑应用...

    大多数数据输入到工作表后都需要进行管理和格式设置,以获得更好的显示效果,也便于分辨各类型的数据.这里我们将介绍行或列的插入与删除和行高和列宽的调整. 一.行或列的插入与删除 在输入数据时,如果遗漏了某 ...

最新文章

  1. 英特尔发布智慧社区解决方案,全栈技术支撑,涵盖五大战略方向
  2. 针对脑出血识别的AI匹配准确性
  3. Airflow安装部署
  4. Qt编写OpenMP程序--循环测试
  5. Docker网络和服务发现
  6. Sun为何一掷千金拿下MySQL?
  7. 零售创新决胜新消费暨2021中国网络零售TOP100榜单
  8. Junit3.8源码--核心类
  9. Selenium自动化测试-6.鼠标键盘操作
  10. configure 查看默认安装路径
  11. 在MOSS2007中使用网页获取部件
  12. Create Material by BDC and BAPI
  13. tomcat内存溢出的解决方法
  14. 计算机管理 未分配磁盘,磁盘显示未分配怎么办?
  15. 超详细讲解:数据库的备份与数据恢复方法举例与说明(完全备份、差异备份、增量备份)
  16. linux登出用户,Linux系统中用户的登入登出命令详解
  17. 2020-10-24 车机UI的SystemUI修改
  18. 基于JAVA郑州卷烟厂库存管理系统计算机毕业设计源码+系统+mysql数据库+lw文档+部署
  19. AspectJ AOP的使用(@Before、@PointCut、@Around等)
  20. 用Python脚本能获取Wifi密码么?能。

热门文章

  1. 关于可重定位目标文件的格式与其符号表的概述
  2. 针对win10的WiFi网络显示“未连接,连接不可用”,系统诊断修复无效
  3. 水星迷你无线路由器ap模式 下要不要启用 dhcp服务器,水星(Mercury)Mini无线路由器Router模式设置...
  4. 电磁继电器和固态继电器区别
  5. 微软Hololens遭遇失败,前途何在?
  6. 2022年中国PCB企业五虎上将是哪几家?
  7. MySQL的索引下推
  8. 虚幻引擎安装失败:先决条件失败 IS-PQR23
  9. firstChild
  10. 在印度,越来越多的女性游戏开发者参与其中