Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set multi-line for EditText's HINT

I know that I could change the No. of lines for EditeText's Text, yet could I change that of EditText's hint as well?

I could not find a solution online.

Thanks for the help.

My Code:

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.property_search, menu);
    super.onCreateOptionsMenu(menu, inflater);

    final MenuItem searchViewMenuItem = menu.findItem(R.id.action_search);
    mSearchView = (SearchView) searchViewMenuItem.getActionView();
    int searchSrcTextId = getResources().getIdentifier("android:id/search_src_text", null, null);
    EditText searchEditText = (EditText) mSearchView.findViewById(searchSrcTextId);
    searchEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
   searchEditText.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
    searchEditText.setHint(getString(R.string.search_hint));
}

strings.xml

<string name="search_hint">keyword, location, \nmax price (e.g. 1K, 1M)</string>

What I want is:

keyword, location,

max price (e.g. 1K, 1M)

like image 706
Derekyy Avatar asked Jan 21 '15 06:01

Derekyy


3 Answers

unbelievable but true: setting the long text programmatically instead of setting it in the xml did the trick.

<TextInputEditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textMultiLine|textCapSentences|textAutoCorrect"

Set the text programmatically:

mEditTextRemark.setHint(R.string...);
like image 111
Fabian Köbel Avatar answered Nov 17 '22 11:11

Fabian Köbel


use new line separator \n in ur hint.

like

android:hint="first line of hint \n second line of hint so on.."

in strings

<string name="urhint">first line of hint \n second line of hint so on..</string>

android:hint="@string/urhint"

hope it works..

like image 37
M S Gadag Avatar answered Nov 17 '22 11:11

M S Gadag


Nothing worked for me but:

 <EditText
         android:id="@+id/text"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:inputType="textMultiLine|textLongMessage"
         android:hint="\n"/>

To be honest I don´t understand why.. but including "\n" as hint in the xml did the trick!

Now you can call setHint from Java code:

searchEditText.setHint(getString(R.string.search_hint));

and remove the \n from strings.xml if you want to allow the text split automatically according to the room

<string name="search_hint">keyword, location, max price (e.g. 1K, 1M)</string>
like image 14
Josu Garcia de Albizu Avatar answered Nov 17 '22 12:11

Josu Garcia de Albizu