Home » Android » android EditText hint does not appear

android EditText hint does not appear

Posted by: admin May 14, 2020 Leave a comment

Questions:

It seems to be the most weird thing that I’ve ever come across.

Here is a layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<EditText        
    android:id="@+id/GuessAppEditText"
    android:lines="1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:gravity="center_horizontal"        
    android:inputType="textCapWords"
    android:hint="@string/Hint" />

</RelativeLayout>

The hint of EditText is not shown.

If I remove either android:gravity="center_horizontal" or android:inputType="textCapWords", hint becomes visible.

I have absolutely no idea what has gravity and textCapWords to do with hint. Is it another Android bug or am I doing something wrong? In the former case, what would be a workaround? I want my text to be center-aligned and capitalized and hint to be shown. Or I want too much from poor Android?

How to&Answers:

Just add a single line and it will work, i.e android:ellipsize="start"

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <EditText
        android:id="@+id/GuessAppEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:ellipsize="start"
        android:gravity="center_horizontal"
        android:hint="hint"
        android:inputType="textCapWords"
        android:lines="1" />

</RelativeLayout>

Answer:

Likely that the original accept answer is no longer valid for latest android version, by setting up the hint color will make the hint display:

android:textColorHint="@android:color/darker_gray"

Hope this helps others, tested with Android 5+

Answer:

It appears to be a bug, as noted here. Seems like a few people in that thread have posted work around’s or resolutions you could try. Have you tried to remove the hint and set it programmatically, to see if that is a workaround?

Declare this before onCreate()

EditText guessAppEt;

And this in onCreate()

guessAppEt = (EditText)findViewById(R.id.GuessAppEditText);
guessAppEt.setHint("Your hint here");