Android: EditText hint in single line

2019-01-18 18:32发布

For setting the Single Line in EditText we use android:singleLine="true" but I want to set the single line for the Hint Text, it is large and I want to show it in a one line like:

http://google.myopenid.stackoverflow.com

I am using the following code:

<EditText android:id="@+id/editText1"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:hint="@string/defaultUrl"
    android:singleLine="true" />

Note: defaultUrl is dynamic and very long URL.

3条回答
Explosion°爆炸
2楼-- · 2019-01-18 19:06

Same issue.

Solution:

EditText.setHint("hint content".replace("\n"," "))
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-01-18 19:12

You can use

android:ellipsize="end"

android:maxLines="1"

to show your hint text in single line but you wont be able to see the whole text because android:ellipsize="end" truncates the text at the end.

查看更多
4楼-- · 2019-01-18 19:17

You can try using

android:maxLines="1"
查看更多
登录 后发表回答