如何自动换行单行AutoCompleteTextView的暗示? [英] How to word wrap the hint of a single line AutoCompleteTextView?

查看:1397
本文介绍了如何自动换行单行AutoCompleteTextView的暗示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个AutoCompleteTextView,用户在一个单一的网上搜索来写,即不换行是允许的。使用的android:单线=真正的允许这才能正常工作。

不过,我也希望设置提示时未输入其他文字显示,这文字确实需要多行。我的问题是与Android 4+,提示不裹到几行。随着Android 2.3的,但是,内容也得到包裹,并会显示多行。用户仍无法输入多个行,所以这就是我想要的方式。

使用,例如的android:MAXLINES =2,因为这不利于允许用户在搜索时插入一个换行符。我也试过的android:scrollHorizo​​ntally =FALSE的android:ellipsize =无的android:layout_weight = 1 没有成功。

我如何能得到暗示包裹多条线路,仍然只接受来自用户的单线与Android 4以及任何想法?下面是code我使用的时刻。

 < AutoCompleteTextView
        机器人:ID =@ + ID / autoCompleteTextView1
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_alignParentTop =真
        机器人:completionThreshold =3
        机器人:提示=这是要显示的提示这是相当长,不适合在一线
        机器人:单线=真/>


解决方案

尝试改变SINGLELINE为:

 的android:行=1

而现在禁用输入

EDIT_TEXT.setOnKeyListener(新OnKeyListener()
        {

  @覆盖
        公共布尔安其(视图V,INT键code,KeyEvent的事件)
        {
            如果(键code == KeyEvent.KEY code_ENTER)
            {
                返回true;
            }
            返回false;
        }
    });

I have an AutoCompleteTextView where the user is to write in a single-line search, i.e. no line breaks are allowed. Using android:singleLine="true" allows this to work properly.

However, I also wish to set a hint to display when no other text has been entered, and this text does require more than one line. My problem is that with Android 4+, the hint is not wrapped to several lines. With Android 2.3, however, the content does get wrapped and multiple lines are displayed. Users are still not able enter more than one line, so this is the way I want it.

Using for example android:maxLines="2" does not help since that allows the user to insert a line break when searching. I've also tried android:scrollHorizontally="false" and android:ellipsize="none" and android:layout_weight=1 without success.

Any ideas on how I can get the hint to wrap multiple lines and still only accept a single line from users with Android 4 as well? Below is the code I'm using at the moment.

    <AutoCompleteTextView
        android:id="@+id/autoCompleteTextView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:completionThreshold="3"
        android:hint="This is the hint to be displayed. It's rather long and doesn't fit in one line"
        android:singleLine="true" />

解决方案

Try changing singleLine to:

android:lines="1"

And now to disable "Enter":

EDIT_TEXT.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event)
        {
            if (keyCode == KeyEvent.KEYCODE_ENTER)
            {
                return true;
            }
            return false;
        }
    });

这篇关于如何自动换行单行AutoCompleteTextView的暗示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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