2015-11-11 24 views
3

我需要將提示文字寫入SearchView。我怎樣才能做到這一點?在SearchView Android上包裝提示文本

隨着未來代碼的文本是這個樣子: 「這是一個非常滷味......」

這裏是我的搜索查看:

<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 not wrapping content

回答

0

地址:

android:lines="1" 

現在禁用 「回車」:

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?

+0

mmm「lines」不是SearchView的屬性。而我沒有使用EditText,我正在使用SearchView。 –

0

嘗試使用android:ellipsize="end"

+0

不行,這沒有奏效。順便說一下,SearchView不會顯示屬性ellipsize –