开发者

Android - EditText : Hint disapear when Scroll horizontally is true

开发者 https://www.devze.com 2023-02-24 04:18 出处:网络
I use a EditText view with a (Hint : text) I want to reproduce the (Single line : true) EditText\'s attribute which is deprecated.

I use a EditText view with a (Hint : text)

I want to reproduce the (Single line : true) EditText's attribute which is deprecated.

So I use those attributes and values :

(Lines : 1)

(Max lines : 1)

(Scroll horizontally : true)

And it works fine.

But there is a little problem the (Hint : text) attribute is now hidden.

Ho开发者_StackOverflow社区w can I bring it back?


Ok here's the thing.
The problem wasn't the inputType "text", it was the Gravity.
When you set the Gravity of a TextView to "Center", the "Hint" disappears.
The way to make it back is to set the Ellipsize to "start".

<EditText
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:hint="Hint"
android:inputType="text"
android:gravity="center"
android:ellipsize="start" />


The only thing you need for single line is android:inputType attribute.

    <EditText
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:hint="Hint"
    android:inputType="text" />
0

精彩评论

暂无评论...
验证码 换一张
取 消