48

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?

shA.t
  • 16,580
  • 5
  • 54
  • 111
venuko
  • 481
  • 1
  • 4
  • 3
  • 4
    I can confirm that `editText` is not displaying the hint when `gravity` is `center` or `right` and `singleLine` is set. I am also looking for a solution. – Justin Nov 12 '10 at 17:10
  • 2
    I can no longer edit my last comment, but I wanted to mention that this is a known issue: http://code.google.com/p/android/issues/detail?id=7252 – Justin Nov 12 '10 at 17:21

11 Answers11

73

using android:ellipsize="end" fixed it for me Weird bug !! (but Android has a lot of these weirdo bug)

Someone Somewhere
  • 23,475
  • 11
  • 118
  • 166
58

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"
lal
  • 1,113
  • 1
  • 11
  • 17
  • 2
    Worked for me. Strange behavior. Only one of my apps had this problem, but solved by this. Wonder what's really going on behind. – March3April4 Nov 27 '17 at 01:41
17

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

Kavi
  • 3,880
  • 2
  • 26
  • 23
7

You need to give text color to hint

android:textColorHint="#000000"
josliber
  • 43,891
  • 12
  • 98
  • 133
Ravi Yadav
  • 2,296
  • 3
  • 25
  • 32
  • That's not enough for Android 2.3 (I tested on HTS Desire S). Also should add android:ellipsize="end". – CoolMind Jan 18 '16 at 12:29
2

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);
2

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.

Praveen
  • 90,477
  • 74
  • 177
  • 219
  • 1
    Nope, that's not it. If you read documentation http://developer.android.com/reference/android/R.styleable.html#TextView_scrollHorizontally, when the text you type doesn't fit into the field, android:scrollHorizontally attribute allows the text to scroll within the field (no scroll bars of course). It has nothing to do with the layout scroll. – venuko Aug 31 '10 at 16:36
1

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

shA.t
  • 16,580
  • 5
  • 54
  • 111
Nandagopal T
  • 2,037
  • 9
  • 42
  • 54
1

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>
shA.t
  • 16,580
  • 5
  • 54
  • 111
Hossa The Coder
  • 77
  • 2
  • 10
1

Try changing the hint text color, sometimes the hint color is the same as the background color

android:textColorHint="@color/colorBlack"
  • Hello and welcome! It seems like this answer is basically a repeat of a couple others- –  Feb 15 '19 at 18:16
0

I changed the style to "@style/Base.WidgetMaterialComponents.TextImputEditText". For me it wasn't gravity or color.

Satan Pandeya
  • 3,747
  • 4
  • 27
  • 53
0

In my android studio is dolphin(old version) and I have set compileSdkVersion 33 so this issue come then i compileSdkVersion 32 set. It's working fine. So decrease compileSdkVersion version. enter image description here