2014-09-26 65 views
2

我正在开发一个应用程序。在XML中布局我正在编辑文本并从drawable设置它的背景。Android:编辑文本提示

现在我想要的是 - 我想设置提示绘制,并且还想设置图像中显示的文本。 enter image description here

我试图设置提示,但是当我设置提示时。没关系。但是当我设置了那个时候隐藏的140个字符。

当用户打算输入时,我想保留那140个字符。而每个角色所剩下的角色都会减少。

因此,如何做到这一点请指导我...

+0

使用'TextView'来显示剩余字符和'EditText'上的'TextWatcher'来更新“chars left”计数器。 – reVerse 2014-09-26 13:26:54

+0

你想要做的事情不是** android:提示**。尝试第一位评论员的建议。 – 2014-09-26 13:29:12

回答

6

使用TextWatcherEdiText和使用TextView显示剩余的字符

private TextView mTextView; 
private EditText mEditText; 
private final TextWatcher mTextEditorWatcher = new TextWatcher() { 
    public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
    } 

    public void onTextChanged(CharSequence s, int start, int before, int count) { 
     //This sets a textview to the current length 
     mTextView.setText(String.valueOf(s.length())); 
    } 

    public void afterTextChanged(Editable s) { 
    } 
}; 
mEditText.addTextChangedListener(mTextEditorWatcher); 
0

你必须考虑你的EditText在一个相对布局所以你可以设置一个textview,它的值将在输入单个字母时改变。因此,您需要为此实现Textwatcher。