我正在开发一个应用程序。在 xml 布局中,我正在编辑文本并将其设置为可绘制的背景。
现在我想要的是 - 我想将提示设置为可绘制,还想设置如图所示的文本。
我尝试设置提示,但是当我设置提示时。没关系。但是当我设置 140 个字符时,时间提示隐藏了。
我想在用户要输入时也保留 140 个字符。在每个字符上,剩下的字符都会减少。
那么如何做到这一点请指导我...
最佳答案
在 EdiText
上使用 TextWatcher
并使用 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);
关于android-layout - Android:编辑文本提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26060667/