限制的EditText为单行 [英] restrict edittext to single line

查看:205
本文介绍了限制的EditText为单行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:<一href="http://stackoverflow.com/questions/6909245/android-singleline-true-not-working-for-edittext">android-singleline-true-not-working-for-edittext

<EditText 
    android:id="@+id/searchbox"  
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:lines="1"
    android:scrollHorizontally="true"
    android:ellipsize="end"
    android:layout_weight="1"
    android:layout_marginTop="2dp"
    android:drawablePadding="10dp"
    android:background="@drawable/edittext"
    android:drawableLeft="@drawable/folder_full"
    android:drawableRight="@drawable/search"
    android:paddingLeft="15dp"
    android:hint="search...">
</EditText>

我想作出上述的EditText到只有一行。即使用户presses进入光标不应该得到下到第二行。任何人可以帮助我这样做???

I want to make the above edittext to have only single line. Even if the user presses "enter" the cursor should not get down to the second line. Can anybody help me doing that???

感谢名单。

推荐答案

您忘了这一个<一个href="http://developer.android.com/reference/android/widget/TextView.html#attr_android:singleLine">android:singleLine

<EditText 
    android:id="@+id/searchbox"  
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:lines="1"
    android:scrollHorizontally="true"
    android:ellipsize="end"
    android:layout_weight="1"
    android:layout_marginTop="2dp"
    android:drawablePadding="10dp"
    android:background="@drawable/edittext"
    android:drawableLeft="@drawable/folder_full"
    android:drawableRight="@drawable/search"
    android:paddingLeft="15dp"
    android:hint="search...">
</EditText>

这篇关于限制的EditText为单行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆