安卓的EditText提示 [英] Android EditText Hint
问题描述
我设置了提示为的EditText
,目前提示知名度已经一去不复返了。当用户开始打字,我想删除的提示文本,当光标在可见的EditText
,而不是当用户开始输入的时间。我该怎么办呢?
<的EditText
机器人:以下属性来=10dp
机器人:背景=@可绘制/ edittextbg
机器人:layout_marginLeft =4DP
机器人:layout_marginTop =7DP
机器人:重力=左
机器人:ID =@ + ID / Photo_Comments
机器人:layout_width =150dip
机器人:MAXLINES =1
机器人:提示=写入标题
机器人:最大长度=50
机器人:单线=真
机器人:=了maxWidth100dip
机器人:layout_height =WRAP_CONTENT/>
我不知道是否可用不这样做的一个直接的方式,但你一定有通过code一种解决方法:听的onfocus事件的EditText
的,一旦它获得焦点,设置提示是什么的东西,如 editText.setHint()
:
这可能不是正是你所要做的,但它可能是这样的 -
myEditText.setOnFocusListener(新OnFocusListener(){
公共无效的onfocus(){
myEditText.setHint();
}
});
I have set a hint for an EditText
, currently the hint visibility is gone. When a user starts typing, I want to remove the hint text, when the cursor is visible in the EditText
, not at the time when a user starts to type. How can I do that?
<EditText
android:paddingLeft="10dp"
android:background="@drawable/edittextbg"
android:layout_marginLeft="4dp"
android:layout_marginTop="7dp"
android:gravity="left"
android:id="@+id/Photo_Comments"
android:layout_width="150dip"
android:maxLines="1"
android:hint="Write Caption"
android:maxLength="50"
android:singleLine="true"
android:maxWidth="100dip"
android:layout_height="wrap_content"/>
I don't know whether a direct way of doing this is available or not, but you surely there is a workaround via code: listen for onFocus event of EditText
, and as soon it gains focus, set the hint to be nothing with something like editText.setHint("")
:
This may not be exactly what you have to do, but it may be something like this-
myEditText.setOnFocusListener(new OnFocusListener(){
public void onFocus(){
myEditText.setHint("");
}
});
这篇关于安卓的EditText提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!