【问题标题】:Wrap hint text on SearchView Android在 SearchView Android 上包装提示文本
【发布时间】:2015-11-11 13:30:27
【问题描述】:

我需要包装写在SearchView 中的提示 文本。我怎样才能做到这一点?

在接下来的代码中,文本显示如下:“This is a very lo...”

这是我的搜索视图:

<SearchView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/sv"
        android:queryHint="This is a very long searchview hint"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

编辑

我能够以编程方式做到这一点:

int id = mSvBusqueda.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
EditText editText = (EditText) mSvBusqueda.findViewById(id);
editText.setSingleLine(false);

但我无法让 searchview 容器包裹编辑文本(见图)

【问题讨论】:

    标签: android searchview


    【解决方案1】:

    添加:

    android:lines="1"
    

    现在禁用“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;
            }
        });
    

    How to word wrap the hint of a single line AutoCompleteTextView?

    【讨论】:

    • mmm "lines" 不是 SearchView 的属性。而且我没有使用 EditText,我使用的是 SearchView。
    【解决方案2】:

    尝试使用android:ellipsize="end"

    【讨论】:

    • 不,这不起作用。顺便说一句,属性 ellipsize 不会出现在 SearchView 中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多