Set multi-line for EditText's HINT

后端 未结 5 1912
闹比i
闹比i 2021-02-14 08:03

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.

Thank

相关标签:
5条回答
  • 2021-02-14 08:44

    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>
    
    0 讨论(0)
  • 2021-02-14 08:53

    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..

    0 讨论(0)
  • 2021-02-14 08:57

    set below two lines in your edittext in your xml file

    android:inputType="textMultiLine"
    android:lines="3"
    

    so gives 3 multilines box are display in preview

    0 讨论(0)
  • 2021-02-14 09:01

    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...);
    
    0 讨论(0)
  • 2021-02-14 09:02

    Try this:

    String.xml

    <string name="hint">Hint first line \n Hint second line \n Hint third line</string>
    

    Layout.xml

     <EditText
             android:id="@+id/emailText"   
             android:layout_height="fill_parent"
             android:layout_width="fill_parent"
             android:background="@drawable/login_edittext_background"
             android:imeOptions="actionNext"
             android:inputType="textEmailAddress"
             android:hint="@string/hint"/>
    
    0 讨论(0)
提交回复
热议问题