In my application in android are many EditText fields. And I ran into a problem with hint. It is not disappearing when EditText is focused, but it disappears when I start to write something. How can this problem be fixed? Because I need the hint to disappear when the EditText field is touched.
It is for example:
<EditText
android:layout_width="260dp"
android:layout_height="30dp"
android:ems="10"
android:inputType="text"
android:id="@+id/driv_lic_num_reg"
android:hint="@string/driver_license_numb"
android:textColor="@color/black"
android:textColorHint="@color/grey_hint"
android:background="@drawable/input_field_background"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="2dp"
android:textCursorDrawable="@color/black"
android:textSize="15dp"
android:paddingLeft="10dp"
android:nextFocusDown="@+id/pass_reg"
android:imeOptions="actionNext"
android:maxLines="1"
android:maxLength="50"
android:focusableInTouchMode="true"/>
This is my solution:
The proposed selector solution by windyzboy doesn't work for EditTexts with centered text, because the cursor stays behind the transparent hint text instead of moving to the center.
A good way without polluting your code is to make a custom EditText, since you probably need the same style in the whole application. That way you can avoid adding checks for each EditText separately.
Every Given Solution may work or not I don't know but the Following steps would definitely help.
First Create a dummy focus to restrain the EditText from gaining focus by
Then Normally set hint in your EditText as example:
Finally add the following code in your activity or fragment where you intend
Hint only disappears when you type in any text, not on focus. I don't think that there is any automatic way to do it, may be I am wrong. However, as a workaround I use the following code to remove hint on focus in EditText
This code line can be done that easily way!
Try
in your
onTouch
logic.However your hint must be dissapearing when you clicked on edit text. So re-check your app logic.