san*_*ram 9 android image hint
如何在android中使用Text&image创建EditText提示/占位符.我这样写
<EditText
android:id="@+id/name"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:lines="1"
................................
...............................
android:drwableLeft="@drawable/image1"
android:hint="enter name here"/>
Run Code Online (Sandbox Code Playgroud)
在这里,我们可以在edittext中看到图像和文本(提示),但即使用户在该字段中输入内容,图像仍然可见.我的要求是如果EditText中没有文字显示提示与图像,如果EditText不为空隐藏提示文本和图像
Dio*_*ijn 11
您可以做的是drawableLeft像在xml中一样设置并添加addTextChangedListener到EditText.当键入发生时,将监听此侦听器,如果textsize大于0,则可以检入侦听器.如果是,则只需将drawableLeftxml中的赋值设置为null.
@Override
public void afterTextChanged(Editable s) {
if(s.toString().length() > 0) {
editText.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
} else {
//Assign your image again to the view, otherwise it will always be gone even if the text is 0 again.
editText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.image, 0, 0, 0);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10299 次 |
| 最近记录: |