带有Edittext MaxLines的Android bug

带有Edittext MaxLines的Android bug,android,android-layout,android-edittext,Android,Android Layout,Android Edittext,编辑文本中的MaxLines属性不起作用: <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_marginBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:textC

编辑文本中的MaxLines属性不起作用:

<android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_marginBottom="5dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:textColorHint="@color/colorAccent"
        android:layout_height="wrap_content">
    <EditText
        android:id="@+id/register_userName"
        android:maxLines="1"
        android:textColorHint="@color/colorAccent"
        android:textColor="@color/colorAccent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Name" />
    </android.support.design.widget.TextInputLayout>
虽然我已经为我的编辑文本指定了
android:maxLines=“1”
,编辑文本将转移到我在android 5.1上测试的新行,这在我以前的应用程序上运行良好,但我最近更新了我的构建工具,我不确定为什么
android:maxLines=“1”
不能按预期工作。

android:singleLine=“true”
已弃用。尝试添加

android:inputType="text"

添加适当的
EditText
行值:

android:lines="1"
android:minLines="1"
android:maxLines="1"

使用所有3个选项都意味着一行。

现在,您应该将
inputType=“text”
maxLines=“1”
一起用于一行

关于为什么不推荐它的讨论:

谷歌问题:

尽管它似乎与android:inputType=“text”一起使用,但文档称它必须与
textmultile一起使用

使文本视图最多有这么多行。当用于 可编辑文本,inputType属性的值必须与 要应用的maxLines属性的textMultiLine标志


因此,现在您必须为单个视图提供3种不同的描述,而不是一个
单行
?因为它被弃用了?哇,这是对更好实践的改进,gj谷歌开发者。@DavidK,这是我遇到的一个黑客,它不会造成任何大的松动。如果它能工作,那就很酷了。但是为什么不赞成一种只使用一行就能产生相同效果的方法呢?这就是我想知道的。好极了,这不像是一个单一的财产。。。所以,是的,如果您希望内部文本是单行的,并且限制键盘显示done而不是换行符,那么仍然需要单行属性。
android:lines="1"
android:minLines="1"
android:maxLines="1"