Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
752 views
in Technique[技术] by (71.8m points)

android - how to make hint disappear when edittext is touched?

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"/>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can also custom your XML code by using Selector. Here is an example code.

Create a selector. In file selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:color="@android:color/transparent" />
    <item android:color="@color/gray" />
</selector>

In your view

android:textColorHint="@drawable/selector"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...