Reputation: 3435
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?
Upvotes: 10
Views: 9544
Reputation: 2027
it's 2021 and this still seems to be an issue, so for anyone running trying to use an EditText and not seeing the hint in the designer you can add tools:background="@android:color/transparent"
or assign any color to the background and the hint will appear.
Upvotes: 1
Reputation: 2295
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+
Upvotes: 5
Reputation: 1544
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>
Upvotes: 23
Reputation: 8925
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");
Upvotes: 0