【问题标题】:How to make multiline edittext in android如何在android中制作多行edittext
【发布时间】:2012-07-29 05:39:26
【问题描述】:

我尝试使用 LayoutParams.MATCHPARENT 为其宽度和高度动态创建一个编辑文本。 下面的代码我试过了,还是不行。

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);

上面的代码让我输入了几行,键盘上会显示一个“ENTER”按钮,但是当我在编辑文本上键入时,如果宽度不足以显示文本,编辑文本会水平滚动。 有人可以帮我如何制作edittext多行吗?

【问题讨论】:

  • 有什么话吗?你成功了吗?我也有同样的问题

标签: android android-edittext multiline


【解决方案1】:

试试

android:scrollHorizontally="false"

对于编辑文本

【讨论】:

    【解决方案2】:

    试试下面的代码

    editor.setSingleLine(false);
    editor.setHorizontalScrollBarEnabled(false);
    

    【讨论】:

      【解决方案3】:

      在您的代码中添加以下行,它可能会对您有所帮助。

      editor.setSingleLine(false);
      

      【讨论】:

        【解决方案4】:

        试试这个代码

            txt.setSingleLine(false);
            txt.setLines(14);
            txt.setMinLines(13);
            txt.setMaxLines(15);
            txt.setGravity(Gravity.LEFT | Gravity.TOP);
        

        【讨论】:

        • 您好,您的帖子已被标记为“低质量”,可能是因为它仅包含代码。您可以通过解释这究竟是如何以及为什么回答问题来大大改进您的答案?
        猜你喜欢
        • 2016-03-29
        • 1970-01-01
        • 1970-01-01
        • 2015-04-15
        • 1970-01-01
        • 2013-06-13
        • 2017-07-09
        • 2012-06-22
        • 2013-03-18
        相关资源
        最近更新 更多