[英]How to make multiline edittext in android
I try to create an edittext dynamically with LayoutParams.MATCHPARENT for its both width and height. 我尝试使用LayoutParams.MATCHPARENT为其宽度和高度动态创建一个edittext。 I have tried the following code, but it is still not working.
我已经尝试了以下代码,但它仍然无法正常工作。
EditText editor = ....;
LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1);
editor.setLayoutParams(params);
editor.setGravity(Gravity.LEFT | Gravity.TOP);
editor.setBackgroundColor(Color.WHITE);
editor.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
editor.setTextColor(Color.BLACK);
//editor.setSingleLine(false);
editor.setFocusableInTouchMode(true);
editor.setInputType(EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE | EditorInfo.TYPE_TEXT_FLAG_IME_MULTI_LINE);
editor.setMaxLines(Integer.MAX_VALUE);
editor.setHorizontallyScrolling(false);
editor.setTransformationMethod(null);
The code above let me to enter several lines, and an 'ENTER' button is displayed in the keyboard, but as I type on the edittext, the edit text scrolls horizontally if the width is not enough to display the text. 上面的代码让我输入几行,并在键盘上显示一个“ENTER”按钮,但是当我在edittext上输入时,如果宽度不足以显示文本,则编辑文本会水平滚动。 Can anybody please help me how to make the edittext multiline?
任何人都可以帮我如何使edittext多线?
Try this following code 请尝试以下代码
editor.setSingleLine(false);
editor.setHorizontalScrollBarEnabled(false);
Try this code 试试这个代码
txt.setSingleLine(false);
txt.setLines(14);
txt.setMinLines(13);
txt.setMaxLines(15);
txt.setGravity(Gravity.LEFT | Gravity.TOP);
Try 尝试
android:scrollHorizontally="false"
for the edittext 对于edittext
将以下行添加到您的代码中,它可能会对您有所帮助。
editor.setSingleLine(false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.