Tuesday, May 17, 2011

Hint Not Displaying When changing Alignment in EditText

This issue is due to the choice of adding gravity to center the text. There is a known bug in the SDK that, as of 2.3, it looks like is still not fixed. This bug hides the hint text when android:singleLine and any custom value of android:gravity are set together. Your choice at this juncture really is to remove one or the other. Some workaround options:
  1. Remove the android:gravity declaration and have the text left-aligned.
  2. Keep the declaration and remove android:singleLine. In this case, you will probably have to override the Editor Action in order to get the default Next or Done button on the soft keypad.
  3. replace parameter android:singleLine to android:maxLine
  4. Remove android:gravity, and set layout_width="wrap_content". Then appropriately center the entire widget in the parent layout. This may look a little goofy with the standard EditText background as it will grow and shrink. You may have to set this to null and make the background part of a parent container.
Also, don't forget to star the bug :)
and leave the comments

Source :

No comments: