EditText hint doesn't show

2019-01-17 02:41发布

My EditText configured as follows won't show the hint:

<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="right"
    android:hint="The hint..."
    android:scrollHorizontally="true"
    android:singleLine="true" />

It works if I set android:gravity="left" or if I remove android:scrollHorizontally and android:singleLine attributes, which is not desirable. Any suggestions?

8条回答
贼婆χ
2楼-- · 2019-01-17 02:55

I wanted my single-line EditText box to scroll but keep the hint on the right also. I had the same issue and got the hint to stick by keeping gravity="right", and setting singleLine="true" and ellipsize="end".

查看更多
劫难
3楼-- · 2019-01-17 02:59

Using android:ellipsize="end" resolves the obvious platform bug. Unfortunately, Xperias still misbehave :(

I found no other solution than to:

if (android.os.Build.MANUFACTURER.matches(".*[Ss]ony.*"))
      editText.setGravity(Gravity.LEFT);
else
      editText.setGravity(Gravity.CENTER);
查看更多
放我归山
4楼-- · 2019-01-17 03:01

The below worked for me:

<EditText
    android:id="@+id/UserText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_alignRight="@+id/UserPassword"
    android:layout_marginTop="85dp"
    android:ems="10"
    android:hint="@string/UserHint"
    android:inputType="textPersonName"
    android:singleLine="true"
    android:text="@string/UserName" >

    <requestFocus />
</EditText>
查看更多
小情绪 Triste *
5楼-- · 2019-01-17 03:06

No need of android:scrollHorizontally attribute. Remove it.EditText is a fixed item on the screen. we want scroll the layout contains the EditText is enough. that is the best design too. you have put android:ellipsize="end" instead of android:scrollHorizontally.

查看更多
来,给爷笑一个
6楼-- · 2019-01-17 03:10

In Lollipop version the default text and hint text color is white for EditText. So we have to change like this in EditText

android:textColorHint="@color/grey"
查看更多
可以哭但决不认输i
7楼-- · 2019-01-17 03:10

This is how, I did for by EditText to have hint in it.

<EditText
    android:id="@+id/productQuantity"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="right|center_vertical"
    android:hint="@string/quantity"
    android:inputType="numberSigned"
    android:ellipsize="end"
    android:singleLine="true" >
</EditText>

Screenshot of what the above code should look like

查看更多
登录 后发表回答