android-layout - Android:编辑文本提示

标签 android-layout android-edittext android

我正在开发一个应用程序。在 xml 布局中,我正在编辑文本并将其设置为可绘制的背景。

现在我想要的是 - 我想将提示设置为可绘制,还想设置如图所示的文本。 enter image description here

我尝试设置提示,但是当我设置提示时。没关系。但是当我设置 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/

相关文章:

Android:Listview 不使用键盘向上移动

android - 如何将焦点监听器设置为编辑文本的中心

android - fragment 中的 Onbackpressed 在实现接口(interface)时不起作用

充当信标的 Android 设备

android - 如何在约束布局中创建副本并对齐一组 View ?

android - 在 Intellij IDEA/Android Studio 中使用合并根标签预览布局

安卓 : PopupWindow fill space above keyboard

android - 具有 3 个可变维度子项的 LinearLayout

android - 编辑文字相互重叠

android - 为 Android 响应 native 推送通知