如何在Android的EditText视图中允许多行?
#1楼
这对我有用 ,实际上这两个属性很重要: 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" />
#2楼
所有这些都很好,但是如果您在上层滚动视图中有您的edittext,则无法工作:)也许最常见的例子是“设置”视图,它有很多项目,超出了可见区域。 在这种情况下,您将它们全部放入滚动视图以使设置可滚动。 如果您在设置中需要多行可滚动编辑文本,则其滚动将不起作用。
#3楼
试试这个,将这些行添加到编辑文本视图中,我将添加我的。 确保你理解它
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类make点击listner到这个编辑文本如下,我将根据你的添加我的,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;
}
});
这对我来说很好
#4楼
android:scrollHorizontally="false"
如果它在xml中不起作用,那么以编程方式执行它会很奇怪。
listView.setHorizontallyScrolling(false);
#5楼
要禁用先前在主题使用xml属性中分配的行数: android:lines="@null"